Skip to content

Commit

Permalink
Merge pull request #666 from tighten/jbk/php-cs-fixer
Browse files Browse the repository at this point in the history
Re-configure and run PHP-CS-Fixer
  • Loading branch information
bakerkretzmar authored Nov 11, 2022
2 parents fdf6db6 + 308d7a3 commit 1438833
Show file tree
Hide file tree
Showing 65 changed files with 331 additions and 281 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at https://editorconfig.org

root = true

[*]
Expand All @@ -15,4 +12,4 @@ trim_trailing_whitespace = true
trim_trailing_whitespace = false

[*.yml]
indent_size = 2
indent_size = 2
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@

# Move dotenv file snapshot test
a2f33e083680337ba53704e4daf8c2d9ed2ac2f8

# Format
ec8c6c07e290fa3c85fd7a1975d1bee0f0d417b9

# Format
12148101ebd2a945d581bf17a7d3c7ed139250cb
34 changes: 34 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Format
on:
pull_request:
paths: ['**.php']
jobs:
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
- uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- uses: ramsey/composer-install@v2
- name: Run PHP-CS-Fixer
id: format
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings
run: |
delimiter=$RANDOM
echo "summary<<${delimiter}" >> $GITHUB_OUTPUT
composer format >> $GITHUB_OUTPUT
echo $delimiter >> $GITHUB_OUTPUT
- name: Check for fixed files
run: echo "changed=$(git diff --quiet && echo false || echo true)" >> $GITHUB_ENV
- name: Commit changes
if: ${{ env.changed == 'true' }}
run: |
git config --global user.name github-actions
git config --global user.email github-actions[bot]@users.noreply.github.com
# awk trims leading and trailing whitespace from each line, sed removes the last two lines
git commit -a -m "Format" -m "$(echo '${{ steps.format.outputs.summary }})' | awk '{$1=$1};1' | sed '$d' | sed '$d')"
git push
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches: [main, ci]
jobs:
test:
phpunit:
name: PHP ${{ matrix.php }}, ${{ matrix.dependencies }}
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.php == '8.2' }}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vendor/
.php-cs-fixer.cache
.phpunit.result.cache
.php_cs.cache
composer.lock
49 changes: 49 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

return (new PhpCsFixer\Config)
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)->exclude('tests/snapshots'))
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'align_multiline_comment' => [
'comment_type' => 'all_multiline',
],
'binary_operator_spaces' => [
'operators' => [
'|' => 'single_space', // Doesn't apply to union types
],
],
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_statement' => [
'statements' => ['return', 'throw'],
],
'concat_space' => [
'spacing' => 'one',
],
'get_class_to_class_keyword' => true,
'global_namespace_import' => [
'import_classes' => true,
],
'new_with_braces' => false,
'no_empty_comment' => false,
'no_useless_else' => true,
'not_operator_with_successor_space' => true,
'php_unit_method_casing' => false,
'phpdoc_annotation_without_dot' => false,
'phpdoc_to_comment' => [
'ignored_tags' => ['var'],
],
'phpdoc_separation' => [
'groups' => [
['test', 'group', 'dataProvider', 'doesNotPerformAssertions'],
],
],
'phpdoc_var_annotation_correct_order' => true,
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => ['arrays', 'arguments', 'parameters'],
],
'yoda_style' => false,
]);
23 changes: 0 additions & 23 deletions .php_cs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@
"jigsaw"
],
"scripts": {
"fix" : "php vendor/bin/php-cs-fixer fix --using-cache=no"
"format" : "php-cs-fixer fix --verbose"
},
"config": {
"sort-packages": true,
"preferred-install": "dist",
"optimize-autoloader": true
"optimize-autoloader": true,
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/CollectionPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private function getPageLink($file, $pageNumber)
$file->getFilenameWithoutExtension(),
'html',
$pageNumber,
$this->prefix
$this->prefix,
);

return $link !== '/' ? rightTrimPath($link) : $link;
Expand Down
2 changes: 1 addition & 1 deletion src/CollectionItemHandlers/BladeCollectionItemHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getItemVariables($file)

return array_merge(
$frontMatter,
['extends' => $extendsFromBladeContent ?: Arr::get($frontMatter, 'extends')]
['extends' => $extendsFromBladeContent ?: Arr::get($frontMatter, 'extends')],
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Console/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private function includeEnvironmentConfig($env)
$this->app->config->put('collections', $this->app->config->get('collections')->map(
function ($envConfig, $key) use ($baseConfig) {
return array_merge($baseConfig->get('collections')->get($key), $envConfig);
}
},
));
}
}
Expand All @@ -106,7 +106,7 @@ private function getBuildPath($pathType, $env)
$customPath = Arr::get($this->app->config, 'build.' . $pathType);
$buildPath = $customPath
? $this->getAbsolutePath($customPath)
: Arr::get($this->app->buildPath, $pathType);
: Arr::get($this->app->buildPath, $pathType);

return str_replace('{env}', $env, $buildPath ?? '');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function execute(InputInterface $input, OutputInterface $output)
$this->console = new ConsoleSession(
$this->input,
$this->output,
$this->getHelper('question')
$this->getHelper('question'),
);

return (int) $this->fire();
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function writeIntro($env, $useCache = false, $cacheExisted = false)
. $env
. ' site '
. $cacheMessage
. '</>'
. '</>',
);

return $this;
Expand Down Expand Up @@ -111,7 +111,7 @@ public function writeTime($time, $useCache = false, $cacheExisted = false)
'<fg=yellow>Build time: </><fg=white>' .
$time .
' seconds</> ' .
$cacheMessage
$cacheMessage,
);

return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/Console/ConsoleSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function ask($question, $default = null, $choices = null, $errorMessage =
return $this->question->ask(
$this->input,
$this->output,
$question
$question,
);
}

Expand All @@ -76,7 +76,7 @@ public function confirm($question, $default = false, $errorMessage = '')
return (bool) $this->question->ask(
$this->input,
$this->output,
new ConfirmationQuestion($question . $defaultPrompt, $default ?? false)
new ConfirmationQuestion($question . $defaultPrompt, $default ?? false),
);
}
}
4 changes: 2 additions & 2 deletions src/Console/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected function configure()
->addArgument(
'preset',
InputArgument::OPTIONAL,
'Which preset should we use to initialize this project?'
'Which preset should we use to initialize this project?',
);
}

Expand Down Expand Up @@ -67,7 +67,7 @@ protected function fire()

case 'd':
if ($this->console->confirm(
'<fg=red>Are you sure you want to delete your existing site?</>'
'<fg=red>Are you sure you want to delete your existing site?</>',
)) {
$this->console->comment('Deleting your existing site...');
$scaffold->deleteExistingSite();
Expand Down
10 changes: 5 additions & 5 deletions src/Console/ServeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,27 @@ protected function configure()
'environment',
InputArgument::OPTIONAL,
'What environment should we serve?',
'local'
'local',
)
->addOption(
'host',
null,
InputOption::VALUE_OPTIONAL,
'What hostname or ip address should we use?',
'localhost'
'localhost',
)
->addOption(
'port',
'p',
InputOption::VALUE_REQUIRED,
'What port should we use?',
8000
8000,
)
->addOption(
'no-build',
null,
InputOption::VALUE_NONE,
'Skip build before serving?'
'Skip build before serving?',
);
}

Expand Down Expand Up @@ -79,7 +79,7 @@ private function getBuildPath($env)
$customBuildPath = Arr::get(
$environmentConfig,
'build.destination',
Arr::get($this->app->config, 'build.destination')
Arr::get($this->app->config, 'build.destination'),
);

$buildPath = $customBuildPath ? $this->getAbsolutePath($customBuildPath) : $this->app->buildPath['destination'];
Expand Down
4 changes: 2 additions & 2 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private function loadConfiguration(): void

if ($config->get('collections')) {
$config->put('collections', collect($config->get('collections'))->flatMap(
fn ($value, $key) => is_array($value) ? [$key => $value] : [$value => []]
fn ($value, $key) => is_array($value) ? [$key => $value] : [$value => []],
));
}

Expand Down Expand Up @@ -147,7 +147,7 @@ private function fireAppCallbacks(array &$callbacks): void
while ($index < count($callbacks)) {
$callbacks[$index]($this);

$index++;
++$index;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Events/EventBus.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
*/
class EventBus
{
/** @var \Illuminate\Support\Collection $beforeBuild */
/** @var \Illuminate\Support\Collection */
public $beforeBuild;

/** @var \Illuminate\Support\Collection $afterCollections */
/** @var \Illuminate\Support\Collection */
public $afterCollections;

/** @var \Illuminate\Support\Collection $afterBuild */
/** @var \Illuminate\Support\Collection */
public $afterBuild;

public function __construct()
Expand Down
2 changes: 0 additions & 2 deletions src/File/CopyFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace TightenCo\Jigsaw\File;

use TightenCo\Jigsaw\File\InputFile;

class CopyFile extends OutputFile
{
protected $source;
Expand Down
6 changes: 3 additions & 3 deletions src/File/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,23 @@ public function files($directory, $match = [], $ignore = [], $ignore_dotfiles =
{
return $directory ? iterator_to_array(
$this->getFinder($directory, $match, $ignore, $ignore_dotfiles)->files(),
false
false,
) : [];
}

public function directories($directory, $match = [], $ignore = [], $ignore_dotfiles = false)
{
return $directory ? iterator_to_array(
$this->getFinder($directory, $match, $ignore, $ignore_dotfiles)->directories(),
false
false,
) : [];
}

public function filesAndDirectories($directory, $match = [], $ignore = [], $ignore_dotfiles = false)
{
return $directory ? iterator_to_array(
$this->getFinder($directory, $match, $ignore, $ignore_dotfiles),
false
false,
) : [];
}

Expand Down
1 change: 0 additions & 1 deletion src/File/OutputFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace TightenCo\Jigsaw\File;

use TightenCo\Jigsaw\File\InputFile;
use TightenCo\Jigsaw\PageData;

class OutputFile
Expand Down
2 changes: 1 addition & 1 deletion src/File/TemporaryFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function get($originalFilename, $extension)
$file = new SplFileInfo(
$this->buildTempPath($originalFilename, $extension),
$this->tempPath,
$originalFilename . $extension
$originalFilename . $extension,
);

return $file->isReadable() ? new InputFile($file) : null;
Expand Down
Loading

0 comments on commit 1438833

Please sign in to comment.