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

Upgrade PHPStan #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ vendor
composer.lock
/.phpcs-cache
/phpcs.xml
/phpstan.neon
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- stage: Code Quality
env: STATIC_ANALYSIS
script:
- vendor/bin/phpstan analyse --ansi --no-progress -l max -c phpstan.neon src/ tests/
- vendor/bin/phpstan analyse --ansi --no-progress

- stage: Code Quality
env: CODING_STANDARDS
Expand Down
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"require-dev": {
"doctrine/coding-standard": "^3.0",
"nette/tester": "~1.7",
"phpstan/phpstan": "^0.9",
"phpstan/phpstan-strict-rules": "^0.9"
"phpstan/phpstan": "^0.11.8",
"phpstan/phpstan-strict-rules": "^0.11.1",
"phpstan/extension-installer": "^1.0"
},
"autoload": {
"psr-4": {
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon

This file was deleted.

7 changes: 7 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
memory-limit: -1
level: max

paths:
- %currentWorkingDirectory%/src
- %currentWorkingDirectory%/tests
15 changes: 2 additions & 13 deletions src/Provider/ConstantProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
use Kdyby\DateTimeProvider\NotImplementedException;
use Kdyby\StrictObjects\Scream;
use function date_default_timezone_get;
use function get_class;
use function gettype;
use function is_numeric;
use function is_object;
use function is_string;
use function sprintf;

/**
Expand All @@ -49,16 +45,9 @@ public function create($dateTime) : ConstantProvider
return new ConstantProvider((new DateTimeImmutable(sprintf('@%.6f', $dateTime)))->setTimezone(new DateTimeZone(date_default_timezone_get())));
}

if (is_string($dateTime)) {
throw new NotImplementedException(sprintf(
'Cannot process datetime in given format "%s"',
$dateTime
));
}

throw new NotImplementedException(sprintf(
'Cannot process datetime from given value %s',
is_object($dateTime) ? get_class($dateTime) : gettype($dateTime)
'Cannot process datetime in given format "%s"',
$dateTime
));
}
}
6 changes: 3 additions & 3 deletions src/Provider/ImmutableProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ trait ImmutableProviderTrait
/**
* Cached date immutable object (time 0:00:00)
*
* @var \DateTimeImmutable|NULL
* @var DateTimeImmutable|null
*/
private $date;

/**
* Cached time object
*
* @var \DateTimeImmutable|NULL
* @var DateInterval|null
*/
private $time;

/**
* Cached time zone object
*
* @var \DateTimeZone|NULL
* @var DateTimeZone|null
*/
private $timezone;

Expand Down
2 changes: 1 addition & 1 deletion src/Provider/ProviderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getDate() : DateTimeImmutable
public function getTime() : DateInterval
{
$interval = new DateInterval(sprintf('PT%dH%dM%dS', $this->getPrototype()->format('G'), $this->getPrototype()->format('i'), $this->getPrototype()->format('s')));
$interval->f = $this->getPrototype()->format('u');
$interval->f = (float) $this->getPrototype()->format('u');

return $interval;
}
Expand Down
4 changes: 0 additions & 4 deletions tests/DateTimeProvider/ConstantProviderFactoryTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ class ConstantProviderFactoryTest extends \Tester\TestCase
Assert::exception(function (): void {
(new ConstantProviderFactory())->create('blablabla');
}, \Kdyby\DateTimeProvider\NotImplementedException::class, 'Cannot process datetime in given format "blablabla"');

Assert::exception(function (): void {
(new ConstantProviderFactory())->create(new stdClass());
}, \Kdyby\DateTimeProvider\NotImplementedException::class, 'Cannot process datetime from given value stdClass');
}

public function testCreateFromMicroseconds(): void
Expand Down