Skip to content
This repository was archived by the owner on Feb 21, 2022. It is now read-only.

Add stricts fixer #27

Merged
merged 1 commit into from
Nov 27, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ use-sort:
sort-type: alph
sort-direction: asc

strict: ~
header: |
/*
* This file is part of the php-formatter package
*
* Copyright (c) 2014 Marc Morera
* Copyright (c) 2014-2016 Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
17 changes: 5 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
language: php

sudo: false

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm-nightly

matrix:
fast_finish: true
allow_failures:
- php: 7.0
- php: hhvm-nightly
- 7.1

install:
- composer install --prefer-source --no-interaction
- composer update --prefer-source --no-interaction

script:
- phpunit --coverage-text
- vendor/bin/phpunit --coverage-text

notifications:
email: false
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use-sort:
sort-type: alph
sort-direction: asc

strict: ~
header: |
/*
* This file is part of the php-formatter package
Expand Down Expand Up @@ -347,3 +348,29 @@ header: |
* @author Marc Morera <[email protected]>
*/
```

### Fix all strict declarations

In your >=7.0 PHP applications you can use simple type declarations in your
methods. You can define your application as relaxed as you want by declaring the
`strict_mode` variable in your files. Each php file must be configured itself,
so in order to make sure all your files have the definition after the header if
exists and before the namespace declaration, you can use this command.

* command: `php-formatter formatter:strict:fix`
* argument: path
* option: --dry-run [***no value***]

You can have three values here. If you define a boolean, then each file found
will have the declaration with the boolean given.

``` yml
strict: true
```

Otherwise, if you define a '~' value then your declaration lines will be
removed.

``` yml
strict: '~'
```
Binary file modified build/php-formatter.phar
100755 → 100644
Binary file not shown.
31 changes: 18 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,22 @@
}
],
"require": {
"php": "^5.4|^7.0",
"symfony/console": "^2.2|^3.0",
"symfony/process": "^2.2|^3.0",
"symfony/finder": "^2.2|^3.0",
"symfony/filesystem": "^2.2|^3.0",
"symfony/yaml": "^2.2|^3.0",
"symfony/event-dispatcher": "^2.2|^3.0",
"symfony/property-access": "^2.2|^3.0"
"php": ">=7.0",
"symfony/console": "^3.0",
"symfony/process": "^3.0",
"symfony/finder": "^3.0",
"symfony/filesystem": "^3.0",
"symfony/yaml": "^3.0",
"symfony/event-dispatcher": "^3.0",
"symfony/property-access": "^3.0"
},
"require-dev": {
"fabpot/php-cs-fixer": "1.4.2",
"phpunit/phpunit": "4.5.0"
"friendsofphp/php-cs-fixer": "^1.12.4",
"phpunit/phpunit": "^5.6.4"
},
"bin": [
"bin/php-formatter"
],
"config": {
"bin-dir": "bin"
},
"autoload": {
"psr-4": {"Mmoreram\\PHPFormatter\\": "src/PHPFormatter"}
},
Expand All @@ -42,5 +39,13 @@
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"scripts": {
"fix-code": [
"vendor/bin/php-cs-fixer fix --config-file=.php_cs",
"vendor/bin/php-formatter f:h:f .",
"vendor/bin/php-formatter f:u:s ."
],
"test": "vendor/bin/phpunit"
}
}
30 changes: 15 additions & 15 deletions src/PHPFormatter/Command/HeaderCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the php-formatter package
*
* Copyright (c) 2014 Marc Morera
* Copyright (c) 2014-2016 Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -29,7 +29,7 @@
use Mmoreram\PHPFormatter\Loader\ConfigLoader;

/**
* Class HeaderCommand
* Class HeaderCommand.
*/
class HeaderCommand extends Command
{
Expand All @@ -41,13 +41,13 @@ class HeaderCommand extends Command
const COMMAND_NAME = 'header';

/**
* configure
* configure.
*/
protected function configure()
{
$this
->setName('formatter:header:fix')
->setDescription('Ensures that all PHP files has header defined in config file')
->setDescription('Ensures that all PHP files have the header defined in the config file')
->addArgument(
'path',
InputArgument::REQUIRED,
Expand All @@ -57,19 +57,19 @@ protected function configure()
'--config',
'-c',
InputOption::VALUE_OPTIONAL,
"Config file directory",
'Config file directory',
getcwd()
)
->addOption(
'dry-run',
null,
InputOption::VALUE_NONE,
"Just print the result, nothing is overwritten"
'Just print the result, nothing is overwritten'
);
}

/**
* Execute command
* Execute command.
*
* @param InputInterface $input Input
* @param OutputInterface $output Output
Expand Down Expand Up @@ -101,11 +101,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
);

if (empty($header)) {
throw new Exception('Header definition must be defined in .formatter.yml file under');
throw new Exception('Header definition must be defined in .formatter.yml file under header');
}

/**
* Building the real directory or file to work in
* Building the real directory or file to work in.
*/
$filesystem = new Filesystem();
if (!$filesystem->isAbsolutePath($path)) {
Expand All @@ -116,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
throw new Exception('Directory or file "' . $path . '" does not exist');
}

/**
/*
* Dry-run message
*/
if ($dryRun && $verbose >= OutputInterface::VERBOSITY_VERBOSE) {
Expand All @@ -128,13 +128,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

/**
* Creates the new HeaderFixer
* Creates the new HeaderFixer.
*/
$headerFixer = new HeaderFixer($header);

$files = $fileFinder->findPHPFilesByPath($path);

/**
/*
* If verbose level is higher or equal than -vv, we print the config
* file data, if is not empty.
*/
Expand All @@ -144,11 +144,11 @@ protected function execute(InputInterface $input, OutputInterface $output)

$output->writeln('#');

/**
/*
* Each found php file is processed
*/
foreach ($files as $file) {
$data = file_get_contents($file);
$data = $file->getContents();
$result = $headerFixer->fix($data);

if ($result === false || $data === $result) {
Expand All @@ -160,7 +160,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (!$dryRun) {
file_put_contents($file, $result);
file_put_contents($file->getRealPath(), $result);
}
}
}
Expand Down
Loading