Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Feature: Zend Coding Standard 2 #52

Open
wants to merge 2 commits into
base: develop
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
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"require-dev": {
"malukenho/docheader": "^0.1.5",
"phpunit/phpunit": "^7.0.2",
"zendframework/zend-coding-standard": "~1.0.0"
"squizlabs/php_codesniffer": "^3.3.2",
"webimpress/coding-standard": "dev-master",
Copy link
Member Author

Choose a reason for hiding this comment

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

Once webimpress/coding-standard#3 has a stable release, these lines can be removed.

"zendframework/zend-coding-standard": "^2.0.0-alpha.1"
},
"conflict": {
"container-interop/container-interop": "<1.2.0"
Expand Down
236 changes: 188 additions & 48 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
<?xml version="1.0"?>
<ruleset name="Zend Framework coding standard">
<rule ref="./vendor/zendframework/zend-coding-standard/ruleset.xml"/>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be added to gitignore?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. Either remove it or add it to .gitignore.

<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>
<exclude-pattern>test/TestAsset/test/test.js</exclude-pattern>

<!-- Include all rules from the Zend Coding Standard -->
<rule ref="ZendCodingStandard"/>
</ruleset>
5 changes: 3 additions & 2 deletions src/TwigEnvironmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ArrayObject;
use DateTimeZone;
use Psr\Container\ContainerInterface;
use Throwable;
use Twig_Environment as TwigEnvironment;
use Twig_Extension_Core as TwigExtensionCore;
use Twig_Extension_Debug as TwigExtensionDebug;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function __invoke(ContainerInterface $container) : TwigEnvironment
if (! is_array($config) && ! $config instanceof ArrayObject) {
throw new Exception\InvalidConfigException(sprintf(
'"config" service must be an array or ArrayObject for the %s to be able to consume it; received %s',
__CLASS__,
self::class,
(is_object($config) ? get_class($config) : gettype($config))
));
}
Expand All @@ -110,7 +111,7 @@ public function __invoke(ContainerInterface $container) : TwigEnvironment
}
try {
$timezone = new DateTimeZone($timezone);
} catch (\Exception $e) {
} catch (Throwable $e) {
Copy link
Member

Choose a reason for hiding this comment

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

This change is not safe as it changes behavior and as such it is not up to a CS tool to decide. Intercepting exceptions is not quite the same as intercepting catchable php errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

In this case you actually want to catch everything. But most cases you catch specific component exceptions like Zend\Expressive\Exception\RuntimeException.

For the few exceptions the sniff can be disabled. Disabling sniffs is documented and so are the sniffs.

throw new Exception\InvalidConfigException(sprintf('Unknown or invalid timezone: "%s"', $timezone));
}
$environment->getExtension(TwigExtensionCore::class)->setTimezone($timezone);
Expand Down
Loading