Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed phpstan level 1 errors #487

Merged
merged 3 commits into from Jan 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/Property/ICalendar/DateTime.php
Expand Up @@ -338,8 +338,8 @@ public function validate($options = 0)
$messages = parent::validate($options);
$valueType = $this->getValueType();
$values = $this->getParts();
try {
foreach ($values as $value) {
foreach ($values as $value) {
phil-davis marked this conversation as resolved.
Show resolved Hide resolved
try {
switch ($valueType) {
case 'DATE':
DateTimeParser::parseDate($value);
Expand All @@ -348,13 +348,14 @@ public function validate($options = 0)
DateTimeParser::parseDateTime($value);
break;
}
} catch (InvalidDataException $e) {
$messages[] = [
'level' => 3,
'message' => 'The supplied value ('.$value.') is not a correct '.$valueType,
'node' => $this,
];
break;
}
} catch (InvalidDataException $e) {
$messages[] = [
'level' => 3,
'message' => 'The supplied value ('.$value.') is not a correct '.$valueType,
'node' => $this,
];
}

return $messages;
Expand Down
7 changes: 7 additions & 0 deletions lib/Recur/RRuleIterator.php
Expand Up @@ -322,14 +322,17 @@ protected function nextDaily()
return;
}

$recurrenceHours = [];
if (!empty($this->byHour)) {
$recurrenceHours = $this->getHours();
}

$recurrenceDays = [];
if (!empty($this->byDay)) {
$recurrenceDays = $this->getDays();
}

$recurrenceMonths = [];
if (!empty($this->byMonth)) {
$recurrenceMonths = $this->getMonths();
}
Expand Down Expand Up @@ -372,10 +375,12 @@ protected function nextWeekly()
return;
}

$recurrenceHours = [];
if ($this->byHour) {
$recurrenceHours = $this->getHours();
}

$recurrenceDays = [];
if ($this->byDay) {
$recurrenceDays = $this->getDays();
}
Expand Down Expand Up @@ -436,6 +441,7 @@ protected function nextMonthly()
return;
}

$occurrence = -1;
while (true) {
$occurrences = $this->getMonthlyOccurrences();

Expand Down Expand Up @@ -605,6 +611,7 @@ protected function nextYearly()
// If we got a byDay or getMonthDay filter, we must first expand
// further.
if ($this->byDay || $this->byMonthDay) {
$occurrence = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which error is fixed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$occurrence may not be defined by the time it is used on line 654.

while (true) {
$occurrences = $this->getMonthlyOccurrences();

Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
@@ -1,2 +1,4 @@
parameters:
level: 0
level: 1
universalObjectCratesClasses:
JeroenVanOort marked this conversation as resolved.
Show resolved Hide resolved
- \Sabre\VObject\Component
10 changes: 8 additions & 2 deletions tests/VObject/CliTest.php
Expand Up @@ -14,8 +14,14 @@ class CliTest extends TestCase
/** @var CliMock */
private $cli;

private $sabreTempDir = __DIR__.'/../temp/';

public function setUp(): void
{
if (!file_exists($this->sabreTempDir)) {
mkdir($this->sabreTempDir);
}

$this->cli = new CliMock();
$this->cli->stderr = fopen('php://memory', 'r+');
$this->cli->stdout = fopen('php://memory', 'r+');
Expand Down Expand Up @@ -269,7 +275,7 @@ public function testConvertMimeDir()

public function testConvertDefaultFormats()
{
$outputFile = SABRE_TEMPDIR.'bar.json';
$outputFile = $this->sabreTempDir.'bar.json';

$this->assertEquals(
2,
Expand All @@ -282,7 +288,7 @@ public function testConvertDefaultFormats()

public function testConvertDefaultFormats2()
{
$outputFile = SABRE_TEMPDIR.'bar.ics';
$outputFile = $this->sabreTempDir.'bar.ics';

$this->assertEquals(
2,
Expand Down
5 changes: 4 additions & 1 deletion tests/VObject/ComponentTest.php
Expand Up @@ -22,9 +22,12 @@ public function testIterate()
foreach ($comp->children() as $key => $subcomponent) {
++$count;
$this->assertInstanceOf('Sabre\\VObject\\Component', $subcomponent);

if (2 === $count) {
$this->assertEquals(1, $key);
}
}
$this->assertEquals(2, $count);
$this->assertEquals(1, $key);
}

public function testMagicGet()
Expand Down
5 changes: 4 additions & 1 deletion tests/VObject/ElementListTest.php
Expand Up @@ -23,8 +23,11 @@ public function testIterate()
foreach ($elemList as $key => $subcomponent) {
++$count;
$this->assertInstanceOf('Sabre\\VObject\\Component', $subcomponent);

if (3 === $count) {
$this->assertEquals(2, $key);
}
}
$this->assertEquals(3, $count);
$this->assertEquals(2, $key);
}
}
1 change: 1 addition & 0 deletions tests/VObject/ITip/BrokerTester.php
Expand Up @@ -45,6 +45,7 @@ public function process($input, $existingObject = null, $expected = false)

$vcal = Reader::read($input);

$mainComponent = new \Sabre\VObject\Component\VEvent($vcal, 'VEVENT');
foreach ($vcal->getComponents() as $mainComponent) {
if ('VEVENT' === $mainComponent->name) {
break;
Expand Down
1 change: 1 addition & 0 deletions tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php
Expand Up @@ -40,6 +40,7 @@ public function testExpand()

$vcal = $vcal->expand(new DateTime('2013-09-28'), new DateTime('2014-09-11'));

$dates = [];
foreach ($vcal->VEVENT as $event) {
$dates[] = $event->DTSTART->getValue();
}
Expand Down
1 change: 1 addition & 0 deletions tests/VObject/Recur/EventIterator/BySetPosHangTest.php
Expand Up @@ -35,6 +35,7 @@ public function testExpand()

$vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2016-01-01'));

$dates = [];
foreach ($vcal->VEVENT as $event) {
$dates[] = $event->DTSTART->getValue();
}
Expand Down
8 changes: 0 additions & 8 deletions tests/bootstrap.php
Expand Up @@ -13,11 +13,3 @@
break;
}
}

if (!defined('SABRE_TEMPDIR')) {
define('SABRE_TEMPDIR', __DIR__.'/temp/');
}

if (!file_exists(SABRE_TEMPDIR)) {
mkdir(SABRE_TEMPDIR);
}