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

Add PHP CS Fixer #4

Merged
merged 1 commit into from Jun 21, 2019
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
10 changes: 10 additions & 0 deletions .editorconfig
@@ -0,0 +1,10 @@
; top-most EditorConfig file
root = true

; Unix-style newlines
[*]
end_of_line = LF
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .gitattributes
@@ -1,6 +1,7 @@
# .gitattributes
tests/ export-ignore
.travis.yml export-ignore
.php_cs export-ignore

# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
/vendor/
/composer.phar
/composer.lock
/.php_cs.cache
45 changes: 45 additions & 0 deletions .php_cs
@@ -0,0 +1,45 @@
<?php

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => [
'syntax' => 'short'
],
'combine_consecutive_unsets' => true,
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block'
],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
// 'psr4' => true,
'strict_comparison' => true,
'strict_param' => true,
'concat_space' => [
'spacing' => 'one'
],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude([
'vendor',
])
->in(__DIR__)
)
;
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -15,6 +15,7 @@ before_script:

script:
- mkdir -p build/logs
- php vendor/bin/php-cs-fixer fix --verbose --dry-run
- php vendor/bin/simple-phpunit -v --coverage-clover build/logs/clover.xml

after_script:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -18,6 +18,7 @@
},
"require-dev": {
"symfony/phpunit-bridge": "^4.2",
"php-coveralls/php-coveralls": "^2.0"
"php-coveralls/php-coveralls": "^2.0",
"friendsofphp/php-cs-fixer": "~2.13"
}
}
15 changes: 8 additions & 7 deletions src/PiwikTwigExtension.php
Expand Up @@ -3,15 +3,15 @@
namespace PiwikTwigExtension;

use InvalidArgumentException;
use Twig_Extension;
use Twig_SimpleFunction;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

/**
* Twig extension for Piwik integration.
*
* @author Matthieu Napoli <matthieu@mnapoli.fr>
*/
class PiwikTwigExtension extends Twig_Extension
class PiwikTwigExtension extends AbstractExtension
{
/**
* @var string|null
Expand Down Expand Up @@ -45,7 +45,7 @@ public function getName()
public function getFunctions()
{
return [
new Twig_SimpleFunction(
new TwigFunction(
'piwik',
[$this, 'generatePiwikTrackerCode'],
['is_safe' => ['html']]
Expand All @@ -56,21 +56,22 @@ public function getFunctions()
/**
* @param string|null $piwikHost
* @param string|null $siteId
*
* @return string
*/
public function generatePiwikTrackerCode($piwikHost = null, $siteId = null)
{
if (! $this->enabled) {
if (!$this->enabled) {
return '';
}

$piwikHost = $piwikHost ?: $this->piwikHost;
$siteId = $siteId ?: $this->siteId;

if ($piwikHost === null) {
if (null === $piwikHost) {
throw new InvalidArgumentException('No Piwik host was configured or given to generate the tracker code');
}
if ($siteId === null) {
if (null === $siteId) {
throw new InvalidArgumentException('No Piwik site ID was configured or given to generate the tracker code');
}

Expand Down