Skip to content

Commit

Permalink
Merge pull request #4 from mnapoli/php-cs-fixer
Browse files Browse the repository at this point in the history
Add PHP CS Fixer
  • Loading branch information
j0k3r committed Jun 21, 2019
2 parents 95cafba + b436838 commit e1746d2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/vendor/
/composer.phar
/composer.lock
/.php_cs.cache
45 changes: 45 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit e1746d2

Please sign in to comment.