Skip to content

Commit

Permalink
Merge pull request #4 from cordoval/4-adding-collateral-files
Browse files Browse the repository at this point in the history
merge #4 adding collateral files (cordoval)

This PR was merged into cordoval:master branch.

Discussion
----------



Commits
-------

9396bfa plug bldr and php_cs (cordoval)
d44290c @sstok said vendor is included by default? (cordoval)
2466c66 cut unfinished calls (cordoval)
f8ca7dc plug fixer (cordoval)
09ea076 plug some cs fixes (cordoval)
7bf8147 short array syntax (cordoval)
  • Loading branch information
cordoval committed Jul 12, 2014
2 parents 4f2144c + 7bf8147 commit 59648c9
Show file tree
Hide file tree
Showing 15 changed files with 373 additions and 9 deletions.
175 changes: 175 additions & 0 deletions .bldr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
bldr:
name: cordoval/matthew-7-12
description: Matthew 7:12 project
profiles:
travisBeforeScript:
description: Travis Profile for running server:run
tasks:
- prepare
- lint
- phpcs
travisScript:
description: Travis Profile to run test suite
tasks:
- test
tdd:
description: Local Development Profile
tasks:
- testLocal
- watch
docker:
description: Docker setup
tasks:
- bootstrap
cs:
description: fix cs for once
tasks:
- runFixer
tasks:
bootstrap:
calls:
-
type: exec
failOnError: true
executable: composer
arguments: [-q, install, --prefer-dist]
-
type: exec
failOnError: true
executable: cp
arguments: [app/config/parameters.yml.docker, app/config/parameters.yml]
-
type: exec
failOnError: true
executable: php
arguments: [app/console, doctrine:schema:update, --force, --env=dev]
-
type: exec
failOnError: true
executable: php
arguments: [app/console, doctrine:mongodb:schema:update, --env=dev]
-
type: exec
failOnError: true
executable: php
arguments: [app/console, cache:clear, --env=dev]
prepare:
calls:
-
type: exec
failOnError: true
executable: cp
arguments: [app/config/parameters.yml.travis, app/config/parameters.yml]
-
type: exec
failOnError: true
executable: composer
arguments: [-q, install, --prefer-dist]
-
type: exec
executable: php
arguments: [app/console, doctrine:database:create, --env=test]
-
type: exec
executable: php
arguments: [app/console, doctrine:schema:create, --env=test]
-
type: exec
executable: php
arguments: [app/console, doctrine:schema:update, --force, --env=test]
-
type: exec
executable: php
arguments: [app/console, doctrine:mongodb:schema:update, --env=test]
-
type: exec
executable: php
arguments: [app/console, cache:clear, --env=test]
lint:
description: Lints the files of the project
calls:
-
type: apply
failOnError: true
src:
- { path: [src], files: *.php, recursive: true }
output: /dev/null
executable: php
arguments: [-l]
phpcs:
description: Runs the PHP Code Sniffer
calls:
-
type: exec
executable: php
arguments:
- bin/phpcs
- --standard=PSR2
- --report=full
- src/
-
type: exec
output: /dev/null
append: false
executable: php
arguments:
- bin/phpcs
- --standard=PSR2
- --report=checkstyle
- --report-file=build/logs/checkstyle.xml
- src/
test:
description: Runs the PHPUnit Tests
calls:
-
type: background
failOnEror: false
executable: ./dev_built_in_server
arguments: []
-
type: exec
failOnError: true
executable: php
arguments:
- bin/phpunit
#- --exclude-group=travis
#- --coverage-text=php://stdout
testLocal:
description: Runs the PHPUnit Tests
calls:
-
type: exec
executable: clear
-
type: exec
executable: php
arguments:
- bin/phpunit
- --stop-on-failure
- --group=now
watch:
description: Watch Task for Local Development
calls:
-
type: watch
src:
- { path: [src], files: *.php, recursive: true }
task: testLocal
runFixer:
description: Installs if not already and runs php-cs-fixer with custom .php_cs
calls:
-
type: exec
executable: curl
arguments:
- http://cs.sensiolabs.org/get/php-cs-fixer.phar
- -S
- -o
- php-cs-fixer.phar
-
type: exec
executable: php
arguments:
- php-cs-fixer.phar
- fix
- .
9 changes: 9 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = spaces
indent_size = 4
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
45 changes: 45 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

require_once __DIR__.'/src/Decoupling/Fixer/ShortArraySyntaxFixer.php';

$finder = Symfony\CS\Finder\DefaultFinder::create()
->notName('README.md')
->notName('composer.*')
->notName('phpunit.xml')
->exclude('app')
->exclude('build')
->exclude('web/bundles')
->in(__DIR__)
;

return Symfony\CS\Config\Config::create()
->addCustomFixer(new Decoupling\Fixer\ShortArraySyntaxFixer)
->fixers(
[
'encoding',
'linefeed',
'indentation',
'trailing_spaces',
'object_operator',
'phpdoc_params',
'visibility',
'short_tag',
'php_closing_tag',
'return',
'extra_empty_lines',
'braces',
'lowercase_constants',
'lowercase_keywords',
'include',
'function_declaration',
'controls_spaces',
'spaces_cast',
'elseif',
'eof_ending',
'one_class_per_file',
'unused_use',
'short_array_syntax'
]
)
->finder($finder)
;
2 changes: 1 addition & 1 deletion app/console
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

set_time_limit(0);

require_once __DIR__.'/vendor/autoload.php';
require_once __DIR__.'/../vendor/autoload.php';

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]
},
"require": {
"symfony/symfony": "2.6.x-dev",
"symfony/symfony": "~2.5.1",
"doctrine/orm": "~2.2,>=2.2.3",
"doctrine/doctrine-bundle": "~1.2.0",
"twig/extensions": "~1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Collabs/ZipperZippy.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function zipAndBreak()

public function unzipAndJoin()
{
foreach(array('archive.zip', 'archive2.zip', 'archive3.zip') as $path) {
foreach (['archive.zip', 'archive2.zip', 'archive3.zip'] as $path) {
$archive = $zipAdapter->open($path);
}

Expand Down
85 changes: 85 additions & 0 deletions src/Decoupling/Fixer/ShortArraySyntaxFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Decoupling\Fixer;

use Symfony\CS\FixerInterface;
use Symfony\CS\Tokens;

class ShortArraySyntaxFixer implements FixerInterface
{
public function fix(\SplFileInfo $file, $content)
{
$tokens = Tokens::fromCode($content);

for ($index = 0, $c = $tokens->count(); $index < $c; $index++) {
$token = $tokens[$index];

if (Tokens::isKeyword($token) && T_ARRAY === $token[0] && '(' === $tokens->getNextNonWhitespace($index)) {
$this->fixArray($tokens, $index);
continue;
}
}

return $tokens->generateCode();
}

private function fixArray(Tokens $tokens, &$index)
{
$bracesLevel = 0;

unset($tokens[$index]);
$index++;

for ($c = $tokens->count(); $index < $c; $index++) {
$token = $tokens[$index];

if ('(' === $token) {
if (0 === $bracesLevel) {
$tokens[$index] = '[';
}

++$bracesLevel;
continue;
}

if (Tokens::isKeyword($token) && T_ARRAY === $token[0] && '(' === $tokens->getNextNonWhitespace($index)) {
$this->fixArray($tokens, $index);
continue;
}

if (')' === $token) {
--$bracesLevel;

if (0 === $bracesLevel) {
$tokens[$index] = ']';
break;
}
}
}
}

public function getLevel()
{
return FixerInterface::ALL_LEVEL;
}

public function getPriority()
{
return 0;
}

public function supports(\SplFileInfo $file)
{
return 'php' === pathinfo($file->getFilename(), PATHINFO_EXTENSION);
}

public function getName()
{
return 'short_array_syntax';
}

public function getDescription()
{
return 'PHP array\'s should use the PHP 5.4 short-syntax';
}
}
48 changes: 48 additions & 0 deletions src/Decoupling/Tests/Fixer/ShortArraySyntaxFixerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace Decoupling\Tests\Fixer;

use Decoupling\Fixer\ShortArraySyntaxFixer;

class ShortArraySyntaxFixerTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider provideExamples
*/
public function testFix($expected, $input)
{
$fixer = new ShortArraySyntaxFixer();
$file = $this->getTestFile();

$this->assertEquals($expected, $fixer->fix($file, $input));
}

public function provideExamples()
{
return [
['<?php $x = [];', '<?php $x = array();'],
['<?php $x = []; $y = [];', '<?php $x = array(); $y = array();'],
['<?php $x = [ ];', '<?php $x = array( );'],
['<?php $x = [\'foo\'];', '<?php $x = array(\'foo\');'],
['<?php $x = [ \'foo\' ];', '<?php $x = array( \'foo\' );'],
['<?php $x = [($y ? true : false)];', '<?php $x = array(($y ? true : false));'],
['<?php $x = [($y ? [true] : [false])];', '<?php $x = array(($y ? array(true) : array(false)));'],//
['<?php $x = [($y ? [true] : [ false ])];', '<?php $x = array(($y ? array(true) : array( false )));'],
['<?php $x = [($y ? ["t" => true] : ["f" => false])];', '<?php $x = array(($y ? array("t" => true) : array("f" => false)));'],
['<?php print_r([($y ? true : false)]);', '<?php print_r(array(($y ? true : false)));'],
['<?php $x = [[[]]];', '<?php $x = array(array(array()));'],
['<?php $x = [[[]]]; $y = [[[]]];', '<?php $x = array(array(array())); $y = array(array(array()));'],
];
}

private function getTestFile($filename = __FILE__)
{
static $files = [];

if (!isset($files[$filename])) {
$files[$filename] = new \SplFileInfo($filename);
}

return $files[$filename];
}
}
Loading

0 comments on commit 59648c9

Please sign in to comment.