Skip to content

Commit

Permalink
Switch to Doctrine CS 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Majkl578 committed Feb 14, 2018
1 parent a9191ee commit 4a8db88
Show file tree
Hide file tree
Showing 17 changed files with 276 additions and 259 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
vendor
composer.lock
/.phpcs-cache
/phpcs.xml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
env: CODING_STANDARDS
php: 7.1
script:
- vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 -sp src/ tests/
- vendor/bin/phpcs

allow_failures:
- php: nightly
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"kdyby/strict-objects": "^1.0"
},
"require-dev": {
"kdyby/coding-standard": "^1.0@dev",
"doctrine/coding-standard": "^3.0",
"nette/tester": "~1.7",
"phpstan/phpstan": "^0.9",
"phpstan/phpstan-strict-rules": "^0.9"
Expand Down
24 changes: 24 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset>
<arg name="basepath" value="."/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>

<!-- Ignore warnings, show progress of the run and show sniff names -->
<arg value="nps"/>

<file>src/</file>
<file>tests/</file>

<rule ref="Doctrine"/>

<rule ref="PSR1.Classes.ClassDeclaration">
<exclude-pattern>src/exceptions.php</exclude-pattern>
</rule>

<rule ref="Squiz.Classes.ClassFileName">
<exclude-pattern>src/exceptions.php</exclude-pattern>
</rule>
</ruleset>
4 changes: 0 additions & 4 deletions ruleset.xml

This file was deleted.

6 changes: 2 additions & 4 deletions src/DateProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Kdyby\DateTimeProvider;

use DateTimeImmutable;

interface DateProviderInterface
{

public function getDate(): DateTimeImmutable;

public function getDate() : DateTimeImmutable;
}
6 changes: 2 additions & 4 deletions src/DateTimeProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Kdyby\DateTimeProvider;

use DateTimeImmutable;

interface DateTimeProviderInterface
{

public function getDateTime(): DateTimeImmutable;

public function getDateTime() : DateTimeImmutable;
}
56 changes: 29 additions & 27 deletions src/Provider/ConstantProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,38 @@
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Kdyby\DateTimeProvider\Provider;

use DateTimeImmutable;

class ConstantProvider
implements
\Kdyby\DateTimeProvider\DateTimeProviderInterface,
\Kdyby\DateTimeProvider\DateProviderInterface,
\Kdyby\DateTimeProvider\TimeProviderInterface,
\Kdyby\DateTimeProvider\TimeZoneProviderInterface
use Kdyby\DateTimeProvider\DateProviderInterface;
use Kdyby\DateTimeProvider\DateTimeProviderInterface;
use Kdyby\DateTimeProvider\TimeProviderInterface;
use Kdyby\DateTimeProvider\TimeZoneProviderInterface;
use Kdyby\StrictObjects\Scream;

class ConstantProvider implements
DateTimeProviderInterface,
DateProviderInterface,
TimeProviderInterface,
TimeZoneProviderInterface
{

use \Kdyby\DateTimeProvider\Provider\ImmutableProviderTrait;
use \Kdyby\StrictObjects\Scream;

/**
* @var \DateTimeImmutable
*/
private $prototype;

public function __construct(DateTimeImmutable $dateTime)
{
$this->prototype = $dateTime;
}

protected function getPrototype(): DateTimeImmutable
{
return $this->prototype;
}

use ImmutableProviderTrait;
use Scream;

/**
* @var \DateTimeImmutable
*/
private $prototype;

public function __construct(DateTimeImmutable $dateTime)
{
$this->prototype = $dateTime;
}

protected function getPrototype() : DateTimeImmutable
{
return $this->prototype;
}
}
67 changes: 35 additions & 32 deletions src/Provider/ConstantProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,51 @@
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Kdyby\DateTimeProvider\Provider;

use DateTime;
use DateTimeImmutable;
use DateTimeZone;
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;

/**
* Helper factory to create ConstantProvider from arbitrary input.
*/
class ConstantProviderFactory
{

use \Kdyby\StrictObjects\Scream;

/**
* @param string|int|\DateTimeImmutable|\DateTime $dateTime
*/
public function create($dateTime): ConstantProvider
{
if ($dateTime instanceof DateTimeImmutable) {
return new ConstantProvider($dateTime);

} elseif ($dateTime instanceof DateTime) {
return new ConstantProvider(DateTimeImmutable::createFromMutable($dateTime));

} elseif (is_numeric($dateTime)) {
return new ConstantProvider((new DateTimeImmutable(sprintf('@%.6f', $dateTime)))->setTimezone(new DateTimeZone(date_default_timezone_get())));

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

} else {
throw new \Kdyby\DateTimeProvider\NotImplementedException(sprintf(
'Cannot process datetime from given value %s',
is_object($dateTime) ? get_class($dateTime) : gettype($dateTime)
));
}
}

use Scream;

/**
* @param string|int|\DateTimeImmutable|\DateTime $dateTime
*/
public function create($dateTime) : ConstantProvider
{
if ($dateTime instanceof DateTimeImmutable) {
return new ConstantProvider($dateTime);
} elseif ($dateTime instanceof DateTime) {
return new ConstantProvider(DateTimeImmutable::createFromMutable($dateTime));
} elseif (is_numeric($dateTime)) {
return new ConstantProvider((new DateTimeImmutable(sprintf('@%.6f', $dateTime)))->setTimezone(new DateTimeZone(date_default_timezone_get())));
} elseif (is_string($dateTime)) {
throw new NotImplementedException(sprintf(
'Cannot process datetime in given format "%s"',
$dateTime
));
} else {
throw new NotImplementedException(sprintf(
'Cannot process datetime from given value %s',
is_object($dateTime) ? get_class($dateTime) : gettype($dateTime)
));
}
}
}
42 changes: 22 additions & 20 deletions src/Provider/CurrentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Kdyby\DateTimeProvider\Provider;

use DateTimeImmutable;

class CurrentProvider
implements
\Kdyby\DateTimeProvider\DateTimeProviderInterface,
\Kdyby\DateTimeProvider\DateProviderInterface,
\Kdyby\DateTimeProvider\TimeProviderInterface,
\Kdyby\DateTimeProvider\TimeZoneProviderInterface
use Kdyby\DateTimeProvider\DateProviderInterface;
use Kdyby\DateTimeProvider\DateTimeProviderInterface;
use Kdyby\DateTimeProvider\TimeProviderInterface;
use Kdyby\DateTimeProvider\TimeZoneProviderInterface;
use Kdyby\StrictObjects\Scream;

class CurrentProvider implements
DateTimeProviderInterface,
DateProviderInterface,
TimeProviderInterface,
TimeZoneProviderInterface
{

use \Kdyby\DateTimeProvider\Provider\ProviderTrait;
use \Kdyby\StrictObjects\Scream;

/**
* {@inheritdoc}
*/
public function getPrototype(): DateTimeImmutable
{
return new DateTimeImmutable();
}

use ProviderTrait;
use Scream;

/**
* {@inheritdoc}
*/
public function getPrototype() : DateTimeImmutable
{
return new DateTimeImmutable();
}
}

0 comments on commit 4a8db88

Please sign in to comment.