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 13, 2018
1 parent 5cf7bb2 commit eb61897
Show file tree
Hide file tree
Showing 12 changed files with 292 additions and 290 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 @@ -31,7 +31,7 @@ jobs:
script:
- vendor/bin/parallel-lint -e php,phpt --exclude vendor .
- vendor/bin/phpstan.phar analyse --ansi --no-progress -l7 -c phpstan.neon src tests
- vendor/bin/phpcs --standard=ruleset.xml --encoding=utf-8 -sp src tests
- vendor/bin/phpcs

- stage: Coverage
before_script:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"symfony/http-kernel": "^3.3|^4.0"
},
"require-dev": {
"kdyby/coding-standard": "^1.0@dev",
"doctrine/coding-standard": "^3.0",
"phpstan/phpstan-shim": "^0.7",
"phpunit/phpunit": "~6.2",
"symfony/yaml": "^3.3|^4.0",
Expand Down
16 changes: 16 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?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"/>
</ruleset>
19 changes: 0 additions & 19 deletions ruleset.xml

This file was deleted.

30 changes: 15 additions & 15 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@
* 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\DateTimeProviderBundle\DependencyInjection;

use Kdyby\StrictObjects\Scream;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

class Configuration implements \Symfony\Component\Config\Definition\ConfigurationInterface
class Configuration implements ConfigurationInterface
{
use Scream;

use \Kdyby\StrictObjects\Scream;
public const TYPE_CURRENT = 'current_time';
public const TYPE_REQUEST_TIME = 'request_time';
public const TYPE_MUTABLE_REQUEST_TIME = 'mutable_request_time';
private const TYPES = [self::TYPE_CURRENT, self::TYPE_REQUEST_TIME, self::TYPE_MUTABLE_REQUEST_TIME];

public const TYPE_CURRENT = 'current_time';
public const TYPE_REQUEST_TIME = 'request_time';
public const TYPE_MUTABLE_REQUEST_TIME = 'mutable_request_time';
private const TYPES = [self::TYPE_CURRENT, self::TYPE_REQUEST_TIME, self::TYPE_MUTABLE_REQUEST_TIME];

public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('kdyby_datetime_provider');
public function getConfigTreeBuilder() : TreeBuilder
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('kdyby_datetime_provider');

// @codingStandardsIgnoreStart
$rootNode
Expand All @@ -44,7 +45,6 @@ public function getConfigTreeBuilder(): TreeBuilder
->end();
// @codingStandardsIgnoreEnd

return $treeBuilder;
}

return $treeBuilder;
}
}
105 changes: 53 additions & 52 deletions src/DependencyInjection/KdybyDateTimeProviderExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,68 +8,69 @@
* 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\DateTimeProviderBundle\DependencyInjection;

use Kdyby\DateTimeProvider\Provider\ConstantProvider;
use Kdyby\DateTimeProvider\Provider\CurrentProvider;
use Kdyby\DateTimeProvider\Provider\MutableProvider;
use Kdyby\StrictObjects\Scream;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use function assert;

class KdybyDateTimeProviderExtension extends \Symfony\Component\HttpKernel\DependencyInjection\Extension
class KdybyDateTimeProviderExtension extends Extension
{

use \Kdyby\StrictObjects\Scream;

public const SERVICE_NAME = 'kdyby.datetime_provider.provider';

public function getAlias(): string
{
return 'kdyby_datetime_provider';
}

/**
* @param mixed[][] $configs
*/
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$this->resolveProvider($config, $container);
}

/**
* @param mixed[] $config
*/
private function resolveProvider(array $config, ContainerBuilder $container): void
{
switch ($config['type']) {
case Configuration::TYPE_CURRENT:
$this->registerAlias($container, CurrentProvider::class);
return;
case Configuration::TYPE_REQUEST_TIME:
$this->registerAlias($container, ConstantProvider::class);

return;
case Configuration::TYPE_MUTABLE_REQUEST_TIME:
$this->registerAlias($container, MutableProvider::class);
return;
}

assert(FALSE);
}

private function registerAlias(ContainerBuilder $container, string $alias): void
{
$container->setAlias(self::SERVICE_NAME, new Alias($alias, TRUE));
}

use Scream;

public const SERVICE_NAME = 'kdyby.datetime_provider.provider';

public function getAlias() : string
{
return 'kdyby_datetime_provider';
}

/**
* @param mixed[][] $configs
*/
public function load(array $configs, ContainerBuilder $container) : void
{
$loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.xml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$this->resolveProvider($config, $container);
}

/**
* @param mixed[] $config
*/
private function resolveProvider(array $config, ContainerBuilder $container) : void
{
switch ($config['type']) {
case Configuration::TYPE_CURRENT:
$this->registerAlias($container, CurrentProvider::class);
return;
case Configuration::TYPE_REQUEST_TIME:
$this->registerAlias($container, ConstantProvider::class);

return;
case Configuration::TYPE_MUTABLE_REQUEST_TIME:
$this->registerAlias($container, MutableProvider::class);
return;
}

assert(false);
}

private function registerAlias(ContainerBuilder $container, string $alias) : void
{
$container->setAlias(self::SERVICE_NAME, new Alias($alias, true));
}
}
24 changes: 12 additions & 12 deletions src/KdybyDateTimeProviderBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,24 @@
* 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\DateTimeProviderBundle;

use Kdyby\StrictObjects\Scream;
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class KdybyDateTimeProviderBundle extends \Symfony\Component\HttpKernel\Bundle\Bundle
class KdybyDateTimeProviderBundle extends Bundle
{
use Scream;

use \Kdyby\StrictObjects\Scream;

public function getContainerExtension(): ExtensionInterface
{
if ($this->extension === NULL) {
$this->extension = $this->createContainerExtension();
}

return $this->extension;
}
public function getContainerExtension() : ExtensionInterface
{
if ($this->extension === null) {
$this->extension = $this->createContainerExtension();
}

return $this->extension;
}
}
39 changes: 20 additions & 19 deletions src/RequestTimeAccessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,33 @@
* 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\DateTimeProviderBundle;

use DateTimeImmutable;
use DateTimeZone;
use Kdyby\StrictObjects\Scream;
use Symfony\Component\HttpFoundation\RequestStack;
use function date_default_timezone_get;
use function sprintf;

class RequestTimeAccessor
{

use \Kdyby\StrictObjects\Scream;

/** @var \Symfony\Component\HttpFoundation\RequestStack */
private $requestStack;

public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

public function getRequestTime(): DateTimeImmutable
{
$request = $this->requestStack->getCurrentRequest();
$time = $request !== NULL ? $request->server->get('REQUEST_TIME_FLOAT') : $_SERVER['REQUEST_TIME_FLOAT'];
return (new DateTimeImmutable(sprintf('@%.6f', $time)))->setTimezone(new DateTimeZone(date_default_timezone_get()));
}

use Scream;

/** @var RequestStack */
private $requestStack;

public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

public function getRequestTime() : DateTimeImmutable
{
$request = $this->requestStack->getCurrentRequest();
$time = $request !== null ? $request->server->get('REQUEST_TIME_FLOAT') : $_SERVER['REQUEST_TIME_FLOAT'];
return (new DateTimeImmutable(sprintf('@%.6f', $time)))->setTimezone(new DateTimeZone(date_default_timezone_get()));
}
}

0 comments on commit eb61897

Please sign in to comment.