Skip to content

Commit 7627ba3

Browse files
committed
Code cleanup
1 parent 9b31044 commit 7627ba3

File tree

6 files changed

+41
-47
lines changed

6 files changed

+41
-47
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
return $config->setFinder(PhpCsFixer\Finder::create()
1212
->exclude('vendor')
1313
->in(__DIR__.'\src')
14+
->in(__DIR__.'\examples')
1415
->in(__DIR__.'\tests')
1516
);

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"require-dev": {
3737
"phpunit/phpunit": "^8.4 | ^9.0",
3838
"friendsofphp/php-cs-fixer": "^3.3",
39-
"phpstan/phpstan": "^1.8"
39+
"phpstan/phpstan": "^1.8",
40+
"phpfui/phpunit-syntax-coverage": "^1.0"
4041
}
4142
}

examples/parseicalendar.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
99
* @link http://icalendar.org/php-library.html
1010
*/
11-
1211
include '../vendor/autoload.php';
1312

1413
/**
@@ -18,9 +17,8 @@
1817
* or leave blank to parse the default file.
1918
*
2019
*/
21-
2220
$icalfile = isset($arg[1]) ? $argv[1] : 'abrahamlincoln.ics';
23-
$icalfeed = file_get_contents($icalfile);
21+
$icalfeed = \file_get_contents($icalfile);
2422

2523
// create the ical object
2624
$icalobj = new \ICalendarOrg\ZCiCal($icalfeed);
@@ -31,28 +29,29 @@
3129

3230
// read back icalendar data that was just parsed
3331
if(isset($icalobj->tree->child))
34-
{
35-
foreach($icalobj->tree->child as $node)
3632
{
37-
if($node->getName() == 'VEVENT')
33+
foreach($icalobj->tree->child as $node)
3834
{
35+
if('VEVENT' == $node->getName())
36+
{
3937
$ecount++;
40-
echo "Event $ecount:\n";
38+
echo "Event {$ecount}:\n";
39+
4140
foreach($node->data as $key => $value)
42-
{
43-
if(is_array($value))
4441
{
45-
for($i = 0; $i < count($value); $i++)
42+
if(\is_array($value))
4643
{
44+
for($i = 0; $i < \count($value); $i++)
45+
{
4746
$p = $value[$i]->getParameters();
48-
echo " $key: " . $value[$i]->getValues() . "\n";
47+
echo " {$key}: " . $value[$i]->getValues() . "\n";
48+
}
4949
}
50-
}
5150
else
52-
{
53-
echo " $key: " . $value->getValues() . "\n";
51+
{
52+
echo " {$key}: " . $value->getValues() . "\n";
53+
}
5454
}
5555
}
5656
}
5757
}
58-
}

examples/recurringdate.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
99
* @link http://icalendar.org/php-library.html
1010
*/
11-
1211
include '../vendor/autoload.php';
1312

1413
/**
@@ -17,33 +16,33 @@
1716
* Recurring date examples with RRULE property
1817
*
1918
*/
20-
2119
$examples =
22-
array(
23-
array(
24-
'name' => "Abraham Lincon's birthday",
25-
'date' => '2015-02-12',
26-
'rule' => 'FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12'
27-
),
20+
[
21+
[
22+
'name' => "Abraham Lincon's birthday",
23+
'date' => '2015-02-12',
24+
'rule' => 'FREQ=YEARLY;INTERVAL=1;BYMONTH=2;BYMONTHDAY=12'
25+
],
2826

29-
array(
30-
'name' => 'Start of U.S. Supreme Court Session (1st Monday in October)',
31-
'date' => '2015-10-01',
32-
'rule' => 'FREQ=YEARLY;INTERVAL=1;BYMONTH=10;BYDAY=1MO'
33-
)
34-
);
27+
[
28+
'name' => 'Start of U.S. Supreme Court Session (1st Monday in October)',
29+
'date' => '2015-10-01',
30+
'rule' => 'FREQ=YEARLY;INTERVAL=1;BYMONTH=10;BYDAY=1MO'
31+
]
32+
];
3533

3634
// Use maxdate to limit # of infinitely repeating events
37-
$maxdate = strtotime('2021-01-01');
35+
$maxdate = \strtotime('2021-01-01');
3836

3937
foreach($examples as $example)
40-
{
38+
{
4139
echo $example['name'] . ":\n";
42-
$rd = new \ICalendarOrg\ZCRecurringDate($example['rule'],strtotime($example['date']));
40+
$rd = new \ICalendarOrg\ZCRecurringDate($example['rule'], \strtotime($example['date']));
4341
$dates = $rd->getDates($maxdate);
42+
4443
foreach($dates as $d)
45-
{
46-
echo ' ' . date('l, F j, Y ',$d) . "\n";
47-
}
44+
{
45+
echo ' ' . \date('l, F j, Y ', $d) . "\n";
46+
}
4847
echo "\n";
49-
}
48+
}

examples/simpleevent.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
99
* @link http://icalendar.org/php-library.html
1010
*/
11-
1211
include '../vendor/autoload.php';
1312

1413
/**
@@ -40,7 +39,7 @@
4039

4140
// UID is a required item in VEVENT, create unique string for this event
4241
// Adding your domain to the end is a good way of creating uniqueness
43-
$uid = date('Y-m-d-H-i-s') . '@demo.icalendar.org';
42+
$uid = \date('Y-m-d-H-i-s') . '@demo.icalendar.org';
4443
$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('UID:' . $uid));
4544

4645
// DTSTAMP is a required item in VEVENT
@@ -51,4 +50,3 @@
5150

5251
// write iCalendar feed to stdout
5352
echo $icalobj->export();
54-

examples/timezoneevent.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,9 @@
88
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html>
99
* @link http://icalendar.org/php-library.html
1010
*/
11-
1211
include '../vendor/autoload.php';
1312

14-
/*
15-
* Create Event Example With Local Timezone
16-
*/
13+
// Create Event Example With Local Timezone
1714

1815
$title = 'Event in New York timezone';
1916
// date/time is in SQL datetime format
@@ -28,7 +25,7 @@
2825
$icalobj = new \ICalendarOrg\ZCiCal();
2926

3027
// Add timezone data
31-
\ICalendarOrg\ZCTimeZoneHelper::getTZNode(substr($event_start,0,4),substr($event_end,0,4),$tzid, $icalobj->curnode);
28+
\ICalendarOrg\ZCTimeZoneHelper::getTZNode(\substr($event_start, 0, 4), \substr($event_end, 0, 4), $tzid, $icalobj->curnode);
3229

3330
// create the event within the ical object
3431
$eventobj = new \ICalendarOrg\ZCiCalNode('VEVENT', $icalobj->curnode);
@@ -44,12 +41,11 @@
4441

4542
// UID is a required item in VEVENT, create unique string for this event
4643
// Adding your domain to the end is a good way of creating uniqueness
47-
$uid = date('Y-m-d-H-i-s') . '@demo.icalendar.org';
44+
$uid = \date('Y-m-d-H-i-s') . '@demo.icalendar.org';
4845
$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('UID:' . $uid));
4946

5047
// DTSTAMP is a required item in VEVENT
5148
$eventobj->addNode(new \ICalendarOrg\ZCiCalDataNode('DTSTAMP:' . \ICalendarOrg\ZDateHelper::fromSqlDateTime()));
5249

5350
// write iCalendar feed to stdout
5451
echo $icalobj->export();
55-

0 commit comments

Comments
 (0)