From 59c69ede132815b771d3883b2e6ba1eae941f0da Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:11:53 -0400 Subject: [PATCH 01/15] Rename `.php_cs` to `.php-cs-fixer.php` --- .php_cs => .php-cs-fixer.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .php_cs => .php-cs-fixer.php (100%) diff --git a/.php_cs b/.php-cs-fixer.php similarity index 100% rename from .php_cs rename to .php-cs-fixer.php From 060884b3143e7e07eb4623bc538d0d9ffd9a11f1 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:19:13 -0400 Subject: [PATCH 02/15] Update filenames --- .gitignore | 2 +- contributing.md => CONTRIBUTING.md | 0 LICENSE.txt => LICENSE | 0 readme.md => README.md | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename contributing.md => CONTRIBUTING.md (100%) rename LICENSE.txt => LICENSE (100%) rename readme.md => README.md (100%) diff --git a/.gitignore b/.gitignore index a31c32a8..48bc9651 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ vendor/ +.php-cs-fixer.cache .phpunit.result.cache -.php_cs.cache composer.lock diff --git a/contributing.md b/CONTRIBUTING.md similarity index 100% rename from contributing.md rename to CONTRIBUTING.md diff --git a/LICENSE.txt b/LICENSE similarity index 100% rename from LICENSE.txt rename to LICENSE diff --git a/readme.md b/README.md similarity index 100% rename from readme.md rename to README.md From 543d6f42a418dd7762c8248a54ac9e7904f27d40 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:19:45 -0400 Subject: [PATCH 03/15] Update PHP-CS-Fixer config --- .php-cs-fixer.php | 48 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 14 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 06340612..3e6fb44e 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,23 +1,43 @@ name('*.php') - ->in(__DIR__ . DIRECTORY_SEPARATOR . 'src') - ->in(__DIR__ . DIRECTORY_SEPARATOR . 'tests'); -return PhpCsFixer\Config::create() +return (new PhpCsFixer\Config) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__) + ->exclude(['vendor', 'tests/snapshots']) + ->name('*.php') + ) ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, '@Symfony' => true, - 'align_multiline_comment' => ['comment_type' => 'all_multiline'], - 'array_syntax' => ['syntax' => 'short'], - 'concat_space' => ['spacing' => 'one'], - 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], + 'align_multiline_comment' => [ + 'comment_type' => 'all_multiline', + ], + 'binary_operator_spaces' => [ + 'operators' => [ + '|' => 'no_space' + ], + ], + 'blank_line_after_opening_tag' => true, + 'blank_line_after_namespace' => true, + 'blank_line_before_statement' => [ + 'statements' => ['return'], + ], + 'concat_space' => [ + 'spacing' => 'one', + ], + // 'no_extra_blank_lines' => ['tokens' => ['extra', 'use']], + 'new_with_braces' => false, + 'no_empty_comment' => false, + 'no_useless_else' => true, 'not_operator_with_successor_space' => true, - 'ordered_imports' => ['sort_algorithm' => 'alpha'], - 'phpdoc_annotation_without_dot' => true, + 'php_unit_method_casing' => false, + 'phpdoc_annotation_without_dot' => false, 'phpdoc_order' => true, - 'trailing_comma_in_multiline_array' => true, + 'trailing_comma_in_multiline' => [ + 'after_heredoc' => true, + 'elements' => ['arrays', 'arguments', 'parameters'], + ], 'yoda_style' => false, - ]) - ->setFinder($finder); + ]); From 938cb59a44b45edb867f7569775f09cad458924b Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:19:49 -0400 Subject: [PATCH 04/15] Wip --- .editorconfig | 5 +---- composer.json | 7 +++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.editorconfig b/.editorconfig index 4025c3ea..090a6e6d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -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 [*] @@ -15,4 +12,4 @@ trim_trailing_whitespace = true trim_trailing_whitespace = false [*.yml] -indent_size = 2 \ No newline at end of file +indent_size = 2 diff --git a/composer.json b/composer.json index 56be8c32..0d44a03b 100644 --- a/composer.json +++ b/composer.json @@ -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 From 8fd745d2603f659883ae75e5c5829d82309d6092 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:23:47 -0400 Subject: [PATCH 05/15] Update rules --- .php-cs-fixer.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 3e6fb44e..55ece8f1 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -16,17 +16,19 @@ ], 'binary_operator_spaces' => [ 'operators' => [ - '|' => 'no_space' + '|' => 'single_space' // Doesn't apply to union types ], ], - 'blank_line_after_opening_tag' => true, 'blank_line_after_namespace' => true, + 'blank_line_after_opening_tag' => true, 'blank_line_before_statement' => [ 'statements' => ['return'], ], 'concat_space' => [ 'spacing' => 'one', ], + // 'declare_strict_types' => true, + 'get_class_to_class_keyword' => true, // 'no_extra_blank_lines' => ['tokens' => ['extra', 'use']], 'new_with_braces' => false, 'no_empty_comment' => false, @@ -35,6 +37,10 @@ 'php_unit_method_casing' => false, 'phpdoc_annotation_without_dot' => false, 'phpdoc_order' => true, + 'phpdoc_to_comment' => [ + 'ignored_tags' => ['var'], + ], + 'phpdoc_var_annotation_correct_order' => true, 'trailing_comma_in_multiline' => [ 'after_heredoc' => true, 'elements' => ['arrays', 'arguments', 'parameters'], From ec8c6c07e290fa3c85fd7a1975d1bee0f0d417b9 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:52:51 -0400 Subject: [PATCH 06/15] Format --- jigsaw-core.php | 16 +++---- src/Collection/CollectionPaginator.php | 2 +- .../BladeCollectionItemHandler.php | 2 +- src/Console/BuildCommand.php | 4 +- src/Console/Command.php | 2 +- src/Console/ConsoleOutput.php | 4 +- src/Console/ConsoleSession.php | 4 +- src/Console/InitCommand.php | 4 +- src/Console/ServeCommand.php | 10 ++-- src/Events/EventBus.php | 6 +-- src/File/CopyFile.php | 2 - src/File/Filesystem.php | 6 +-- src/File/OutputFile.php | 1 - src/File/TemporaryFilesystem.php | 2 +- src/Handlers/BladeHandler.php | 4 +- src/Handlers/CollectionItemHandler.php | 2 +- src/Handlers/DefaultHandler.php | 2 +- src/Handlers/MarkdownHandler.php | 20 ++++---- src/Handlers/PaginatedPageHandler.php | 6 +-- src/Jigsaw.php | 8 ++-- src/Loaders/CollectionDataLoader.php | 1 - src/PathResolvers/CollectionPathResolver.php | 4 +- .../PrettyOutputPathResolver.php | 8 ++-- src/Scaffold/DefaultInstaller.php | 4 +- src/Scaffold/PresetPackage.php | 2 +- src/Scaffold/ScaffoldBuilder.php | 6 +-- src/SiteBuilder.php | 6 +-- src/Support/helpers.php | 4 +- src/View/BladeCompiler.php | 6 +-- tests/AtSymbolInMarkdownTest.php | 16 +++---- tests/BladeComponentTest.php | 15 +++--- tests/CollectionItemTest.php | 44 ++++++++--------- tests/ConfigVariableTest.php | 4 +- tests/CustomCommandTest.php | 6 +-- tests/EventsTest.php | 9 ++-- tests/FilesystemTest.php | 8 ++-- tests/MarkdownExtraTest.php | 24 +++++----- tests/PageDataBindingTest.php | 2 +- tests/PaginationTest.php | 48 +++++++++---------- tests/PermalinkTest.php | 10 ++-- tests/RemoteCollectionsTest.php | 42 ++++++++-------- tests/ScaffoldTest.php | 18 +++---- tests/SiteBuilderTest.php | 26 +++++----- tests/TestCase.php | 2 +- tests/ViewPathTest.php | 2 +- tests/ViewRendererTest.php | 12 ++--- 46 files changed, 213 insertions(+), 223 deletions(-) diff --git a/jigsaw-core.php b/jigsaw-core.php index 6018c356..4ce4c242 100644 --- a/jigsaw-core.php +++ b/jigsaw-core.php @@ -2,7 +2,6 @@ use Dotenv\Dotenv; use Illuminate\Container\Container; -use Illuminate\Contracts\Events\Dispatcher; use Illuminate\View\Engines\CompilerEngine; use Illuminate\View\Engines\EngineResolver; use Illuminate\View\Engines\PhpEngine; @@ -12,9 +11,9 @@ use Mni\FrontYAML\Markdown\MarkdownParser as FrontYAMLMarkdownParser; use Mni\FrontYAML\Parser; use Mni\FrontYAML\YAML\YAMLParser; +use TightenCo\Jigsaw\Collection\CollectionPaginator; use TightenCo\Jigsaw\CollectionItemHandlers\BladeCollectionItemHandler; use TightenCo\Jigsaw\CollectionItemHandlers\MarkdownCollectionItemHandler; -use TightenCo\Jigsaw\Collection\CollectionPaginator; use TightenCo\Jigsaw\Console\ConsoleOutput; use TightenCo\Jigsaw\Events\EventBus; use TightenCo\Jigsaw\Events\FakeDispatcher; @@ -42,12 +41,12 @@ use TightenCo\Jigsaw\View\MarkdownEngine; use TightenCo\Jigsaw\View\ViewRenderer; -if (file_exists(__DIR__.'/vendor/autoload.php')) { - require __DIR__.'/vendor/autoload.php'; +if (file_exists(__DIR__ . '/vendor/autoload.php')) { + require __DIR__ . '/vendor/autoload.php'; } -if (file_exists(getcwd().'/vendor/autoload.php')) { - require getcwd().'/vendor/autoload.php'; +if (file_exists(getcwd() . '/vendor/autoload.php')) { + require getcwd() . '/vendor/autoload.php'; } setlocale(LC_ALL, 'en_US.UTF8'); @@ -59,7 +58,7 @@ $container->instance('cwd', getcwd()); if (file_exists($envPath = $container['cwd'] . '/.env')) { - (Dotenv::createImmutable($container['cwd']))->load(); + Dotenv::createImmutable($container['cwd'])->load(); } $cachePath = $container['cwd'] . '/cache'; @@ -73,6 +72,7 @@ $container->bind('config', function ($c) use ($cachePath) { $config = (new ConfigFile($c['cwd'] . '/config.php', $c['cwd'] . '/helpers.php'))->config; $config->put('view.compiled', $cachePath); + return $config; }); @@ -159,7 +159,7 @@ return new MarkdownHandler($c[TemporaryFilesystem::class], $c[FrontMatterParser::class], $c[ViewRenderer::class]); }); -$container->bind(CollectionPathResolver::class, function ($c ) { +$container->bind(CollectionPathResolver::class, function ($c) { return new CollectionPathResolver($c['outputPathResolver'], $c[ViewRenderer::class]); }); diff --git a/src/Collection/CollectionPaginator.php b/src/Collection/CollectionPaginator.php index f551cc34..224af277 100644 --- a/src/Collection/CollectionPaginator.php +++ b/src/Collection/CollectionPaginator.php @@ -49,7 +49,7 @@ private function getPageLink($file, $pageNumber) $file->getFilenameWithoutExtension(), 'html', $pageNumber, - $this->prefix + $this->prefix, ); return $link !== '/' ? rightTrimPath($link) : $link; diff --git a/src/CollectionItemHandlers/BladeCollectionItemHandler.php b/src/CollectionItemHandlers/BladeCollectionItemHandler.php index 2541de7e..27a51604 100644 --- a/src/CollectionItemHandlers/BladeCollectionItemHandler.php +++ b/src/CollectionItemHandlers/BladeCollectionItemHandler.php @@ -28,7 +28,7 @@ public function getItemVariables($file) return array_merge( $frontMatter, - ['extends' => $extendsFromBladeContent ?: Arr::get($frontMatter, 'extends')] + ['extends' => $extendsFromBladeContent ?: Arr::get($frontMatter, 'extends')], ); } diff --git a/src/Console/BuildCommand.php b/src/Console/BuildCommand.php index fd27a76e..05d53508 100644 --- a/src/Console/BuildCommand.php +++ b/src/Console/BuildCommand.php @@ -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); - } + }, )); } } @@ -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 ?? ''); } diff --git a/src/Console/Command.php b/src/Console/Command.php index c9c1c872..b2da5119 100644 --- a/src/Console/Command.php +++ b/src/Console/Command.php @@ -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(); diff --git a/src/Console/ConsoleOutput.php b/src/Console/ConsoleOutput.php index cb49ee23..66053b37 100644 --- a/src/Console/ConsoleOutput.php +++ b/src/Console/ConsoleOutput.php @@ -81,7 +81,7 @@ public function writeIntro($env, $useCache = false, $cacheExisted = false) . $env . ' site ' . $cacheMessage - . '' + . '', ); return $this; @@ -111,7 +111,7 @@ public function writeTime($time, $useCache = false, $cacheExisted = false) 'Build time: ' . $time . ' seconds ' . - $cacheMessage + $cacheMessage, ); return $this; diff --git a/src/Console/ConsoleSession.php b/src/Console/ConsoleSession.php index 608cf7a6..4634e3f3 100644 --- a/src/Console/ConsoleSession.php +++ b/src/Console/ConsoleSession.php @@ -63,7 +63,7 @@ public function ask($question, $default = null, $choices = null, $errorMessage = return $this->question->ask( $this->input, $this->output, - $question + $question, ); } @@ -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), ); } } diff --git a/src/Console/InitCommand.php b/src/Console/InitCommand.php index b67bab86..de274d3d 100644 --- a/src/Console/InitCommand.php +++ b/src/Console/InitCommand.php @@ -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?', ); } @@ -67,7 +67,7 @@ protected function fire() case 'd': if ($this->console->confirm( - 'Are you sure you want to delete your existing site?' + 'Are you sure you want to delete your existing site?', )) { $this->console->comment('Deleting your existing site...'); $scaffold->deleteExistingSite(); diff --git a/src/Console/ServeCommand.php b/src/Console/ServeCommand.php index ce762410..8f0927a4 100644 --- a/src/Console/ServeCommand.php +++ b/src/Console/ServeCommand.php @@ -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?', ); } @@ -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']; diff --git a/src/Events/EventBus.php b/src/Events/EventBus.php index 58b6129c..dac7f627 100644 --- a/src/Events/EventBus.php +++ b/src/Events/EventBus.php @@ -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() diff --git a/src/File/CopyFile.php b/src/File/CopyFile.php index c677a791..25186b74 100644 --- a/src/File/CopyFile.php +++ b/src/File/CopyFile.php @@ -2,8 +2,6 @@ namespace TightenCo\Jigsaw\File; -use TightenCo\Jigsaw\File\InputFile; - class CopyFile extends OutputFile { protected $source; diff --git a/src/File/Filesystem.php b/src/File/Filesystem.php index 86c68f29..aa9fdcfa 100644 --- a/src/File/Filesystem.php +++ b/src/File/Filesystem.php @@ -32,7 +32,7 @@ public function files($directory, $match = [], $ignore = [], $ignore_dotfiles = { return $directory ? iterator_to_array( $this->getFinder($directory, $match, $ignore, $ignore_dotfiles)->files(), - false + false, ) : []; } @@ -40,7 +40,7 @@ public function directories($directory, $match = [], $ignore = [], $ignore_dotfi { return $directory ? iterator_to_array( $this->getFinder($directory, $match, $ignore, $ignore_dotfiles)->directories(), - false + false, ) : []; } @@ -48,7 +48,7 @@ public function filesAndDirectories($directory, $match = [], $ignore = [], $igno { return $directory ? iterator_to_array( $this->getFinder($directory, $match, $ignore, $ignore_dotfiles), - false + false, ) : []; } diff --git a/src/File/OutputFile.php b/src/File/OutputFile.php index fd423a0a..60bd0687 100644 --- a/src/File/OutputFile.php +++ b/src/File/OutputFile.php @@ -2,7 +2,6 @@ namespace TightenCo\Jigsaw\File; -use TightenCo\Jigsaw\File\InputFile; use TightenCo\Jigsaw\PageData; class OutputFile diff --git a/src/File/TemporaryFilesystem.php b/src/File/TemporaryFilesystem.php index 2bef67ee..293129e5 100644 --- a/src/File/TemporaryFilesystem.php +++ b/src/File/TemporaryFilesystem.php @@ -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; diff --git a/src/Handlers/BladeHandler.php b/src/Handlers/BladeHandler.php index 02b60914..681f8797 100644 --- a/src/Handlers/BladeHandler.php +++ b/src/Handlers/BladeHandler.php @@ -55,7 +55,7 @@ private function buildOutput($file, $pageData) $this->hasFrontMatter ? $this->renderWithFrontMatter($file, $pageData) : $this->render($file->getPathName(), $pageData), - $pageData + $pageData, ), ]); } @@ -83,7 +83,7 @@ private function renderWithFrontMatter($file, $pageData) $bladeFilePath = $this->temporaryFilesystem->put( $this->parser->getBladeContent($file->getContents()), $file->getPathname(), - '.blade.php' + '.blade.php', ); return $this->render($bladeFilePath, $pageData); diff --git a/src/Handlers/CollectionItemHandler.php b/src/Handlers/CollectionItemHandler.php index 62d2ed0e..d25ae513 100644 --- a/src/Handlers/CollectionItemHandler.php +++ b/src/Handlers/CollectionItemHandler.php @@ -66,7 +66,7 @@ public function handle($file, $pageData) basename($path, '.' . $outputFile->extension()), $outputFile->extension(), $outputFile->contents(), - $outputFile->data() + $outputFile->data(), ); })->values(); } diff --git a/src/Handlers/DefaultHandler.php b/src/Handlers/DefaultHandler.php index 0726abd6..d5978155 100644 --- a/src/Handlers/DefaultHandler.php +++ b/src/Handlers/DefaultHandler.php @@ -28,7 +28,7 @@ public function handle($file, $pageData) $file->getRelativePath(), $file->getBasename('.' . $file->getExtension()), $file->getExtension(), - $pageData + $pageData, ), ]); } diff --git a/src/Handlers/MarkdownHandler.php b/src/Handlers/MarkdownHandler.php index a80d106e..aad18753 100644 --- a/src/Handlers/MarkdownHandler.php +++ b/src/Handlers/MarkdownHandler.php @@ -59,7 +59,7 @@ private function buildOutput($file, PageData $pageData) $file->getFileNameWithoutExtension(), $extension == 'php' ? 'html' : $extension, $this->render($file, $pageData, $extends), - $pageData + $pageData, ); }); } @@ -72,24 +72,24 @@ private function render($file, $pageData, $extends) return $this->view->render($cached->getPathname(), $pageData); } elseif ($file->isBladeFile()) { return $this->renderBladeMarkdownFile($file, $uniqueFileName, $pageData, $extends); - } else { - return $this->renderMarkdownFile($file, $uniqueFileName, $pageData, $extends); } + + return $this->renderMarkdownFile($file, $uniqueFileName, $pageData, $extends); } private function renderMarkdownFile($file, $uniqueFileName, $pageData, $extends) { $html = $this->parser->parseMarkdownWithoutFrontMatter( - $this->getEscapedMarkdownContent($file) + $this->getEscapedMarkdownContent($file), ); $wrapper = $this->view->renderString( "@extends('{$extends}')\n" . - "@section('{$pageData->page->section}'){$html}@endsection" + "@section('{$pageData->page->section}'){$html}@endsection", ); return $this->view->render( $this->temporaryFilesystem->put($wrapper, $uniqueFileName, '.php'), - $pageData + $pageData, ); } @@ -102,9 +102,9 @@ private function renderBladeMarkdownFile($file, $uniqueFileName, $pageData, $ext $uniqueFileName, basename($contentPath, '.blade.md'), $pageData, - $extends + $extends, ), - $pageData + $pageData, ); } @@ -113,7 +113,7 @@ private function renderMarkdownContent($file) return $this->temporaryFilesystem->put( $this->getEscapedMarkdownContent($file), $file->getPathname(), - '.blade.md' + '.blade.md', ); } @@ -122,7 +122,7 @@ private function renderBladeWrapper($sourceFileName, $contentFileName, $pageData return $this->temporaryFilesystem->put( $this->makeBladeWrapper($contentFileName, $pageData, $extends), $sourceFileName, - '.blade.php' + '.blade.php', ); } diff --git a/src/Handlers/PaginatedPageHandler.php b/src/Handlers/PaginatedPageHandler.php index cf5de5b9..c0d70d8b 100644 --- a/src/Handlers/PaginatedPageHandler.php +++ b/src/Handlers/PaginatedPageHandler.php @@ -21,7 +21,7 @@ public function __construct( CollectionPaginator $paginator, FrontMatterParser $parser, TemporaryFilesystem $temporaryFilesystem, - ViewRenderer $viewRenderer + ViewRenderer $viewRenderer, ) { $this->paginator = $paginator; $this->parser = $parser; @@ -70,7 +70,7 @@ public function handle($file, PageData $pageData) $this->render($file, $pageData), $pageData, $page->currentPage, - $prefix + $prefix, ); }); } @@ -86,7 +86,7 @@ private function render($file, $pageData) $bladeFilePath = $this->temporaryFilesystem->put( $bladeContent, $file->getPathname(), - '.blade.php' + '.blade.php', ); return $this->view->render($bladeFilePath, $pageData); diff --git a/src/Jigsaw.php b/src/Jigsaw.php index 372177b1..9b38c7c8 100644 --- a/src/Jigsaw.php +++ b/src/Jigsaw.php @@ -2,11 +2,11 @@ namespace TightenCo\Jigsaw; +use Illuminate\Contracts\Container\Container; use Illuminate\Support\Traits\Macroable; use TightenCo\Jigsaw\File\Filesystem; -use TightenCo\Jigsaw\Loaders\DataLoader; use TightenCo\Jigsaw\Loaders\CollectionRemoteItemLoader; -use Illuminate\Contracts\Container\Container; +use TightenCo\Jigsaw\Loaders\DataLoader; class Jigsaw { @@ -27,7 +27,7 @@ public function __construct( Container $app, DataLoader $dataLoader, CollectionRemoteItemLoader $remoteItemLoader, - SiteBuilder $siteBuilder + SiteBuilder $siteBuilder, ) { $this->app = $app; $this->dataLoader = $dataLoader; @@ -76,7 +76,7 @@ protected function buildSite($useCache) ->build( $this->getSourcePath(), $this->getDestinationPath(), - $this->siteData + $this->siteData, ); $this->outputPaths = $this->pageInfo->keys(); diff --git a/src/Loaders/CollectionDataLoader.php b/src/Loaders/CollectionDataLoader.php index f8ab56d2..d5a248f1 100644 --- a/src/Loaders/CollectionDataLoader.php +++ b/src/Loaders/CollectionDataLoader.php @@ -2,7 +2,6 @@ namespace TightenCo\Jigsaw\Loaders; -use Exception; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; use TightenCo\Jigsaw\Collection\Collection; diff --git a/src/PathResolvers/CollectionPathResolver.php b/src/PathResolvers/CollectionPathResolver.php index 2d284ec4..01a359d7 100644 --- a/src/PathResolvers/CollectionPathResolver.php +++ b/src/PathResolvers/CollectionPathResolver.php @@ -20,7 +20,7 @@ public function link($path, $data) { return collect($data->extends)->map(function ($bladeViewPath, $templateKey) use ($path, $data) { return $this->cleanOutputPath( - $this->getPath($path, $data, $this->getExtension($bladeViewPath), $templateKey) + $this->getPath($path, $data, $this->getExtension($bladeViewPath), $templateKey), ); }); } @@ -76,7 +76,7 @@ private function parseShorthand($path, $data) $bracketedParametersReplaced = collect($bracketedParameters[0])->map(function ($param) use ($data) { return ['token' => $param, 'value' => $this->getParameterValue($param, $data)]; - })->reduce(function ($carry, $param) use ($path) { + })->reduce(function ($carry, $param) { return str_replace($param['token'], $param['value'], $carry); }, $path); diff --git a/src/PathResolvers/PrettyOutputPathResolver.php b/src/PathResolvers/PrettyOutputPathResolver.php index ebebe8ca..5b52d64a 100644 --- a/src/PathResolvers/PrettyOutputPathResolver.php +++ b/src/PathResolvers/PrettyOutputPathResolver.php @@ -28,15 +28,15 @@ public function link($path, $name, $type, $page = 1, $prefix = '') public function path($path, $name, $type, $page = 1, $prefix = '') { if ($type === 'html' && $name === 'index' && $page > 1) { - return leftTrimPath(trimPath($path) . '/' . trimPath($prefix . '/' . $page) . '/' . 'index.html'); + return leftTrimPath(trimPath($path) . '/' . trimPath($prefix . '/' . $page) . '/index.html'); } if ($type === 'html' && $name !== 'index') { if ($page > 1) { - return trimPath($path) . '/' . $name . '/' . trimPath($prefix . '/' . $page) . '/' . 'index.html'; + return trimPath($path) . '/' . $name . '/' . trimPath($prefix . '/' . $page) . '/index.html'; } - return trimPath($path) . '/' . $name . '/' . 'index.html'; + return trimPath($path) . '/' . $name . '/index.html'; } if (empty($type)) { @@ -54,7 +54,7 @@ public function directory($path, $name, $type, $page = 1, $prefix = '') if ($type === 'html' && $name !== 'index') { if ($page > 1) { - return trimPath($path) . '/' . $name . '/' . trimPath($prefix . '/' . $page); + return trimPath($path) . '/' . $name . '/' . trimPath($prefix . '/' . $page); } return trimPath($path) . '/' . $name; diff --git a/src/Scaffold/DefaultInstaller.php b/src/Scaffold/DefaultInstaller.php index ba366103..82054fd5 100644 --- a/src/Scaffold/DefaultInstaller.php +++ b/src/Scaffold/DefaultInstaller.php @@ -6,13 +6,13 @@ class DefaultInstaller { - const ALWAYS_IGNORE = [ + public const ALWAYS_IGNORE = [ 'build_*', 'init.php', 'node_modules', 'vendor', ]; - const DEFAULT_COMMANDS = [ + public const DEFAULT_COMMANDS = [ 'composer install', 'npm install', 'npm run dev', diff --git a/src/Scaffold/PresetPackage.php b/src/Scaffold/PresetPackage.php index b3b3bc26..6381df2a 100644 --- a/src/Scaffold/PresetPackage.php +++ b/src/Scaffold/PresetPackage.php @@ -10,7 +10,7 @@ class PresetPackage { - const PRESETS = [ + public const PRESETS = [ 'blog' => 'tightenco/jigsaw-blog-template', 'docs' => 'tightenco/jigsaw-docs-template', ]; diff --git a/src/Scaffold/ScaffoldBuilder.php b/src/Scaffold/ScaffoldBuilder.php index 9a289e86..e8e8312a 100644 --- a/src/Scaffold/ScaffoldBuilder.php +++ b/src/Scaffold/ScaffoldBuilder.php @@ -6,7 +6,7 @@ abstract class ScaffoldBuilder { - const IGNORE_DIRECTORIES = [ + public const IGNORE_DIRECTORIES = [ 'archived', 'node_modules', 'vendor', @@ -119,7 +119,7 @@ protected function allBaseFiles() $this->base, null, self::IGNORE_DIRECTORIES, - $ignore_dotfiles = false + $ignore_dotfiles = false, ); } @@ -137,7 +137,7 @@ protected function writeComposer($content = null) if ($content) { $this->files->put( $this->base . DIRECTORY_SEPARATOR . 'composer.json', - json_encode($content, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) + json_encode($content, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), ); } } diff --git a/src/SiteBuilder.php b/src/SiteBuilder.php index 744331f1..52e414d6 100644 --- a/src/SiteBuilder.php +++ b/src/SiteBuilder.php @@ -21,7 +21,7 @@ public function __construct( $cachePath, $outputPathResolver, ConsoleOutput $consoleOutput, - $handlers = [] + $handlers = [], ) { $this->files = $files; $this->cachePath = $cachePath; @@ -163,7 +163,7 @@ private function getOutputPath($file) $file->name(), $file->extension(), $file->page(), - $file->prefix() + $file->prefix(), ))); } @@ -177,7 +177,7 @@ private function getOutputLink($file) str_replace('\\', '/', $file->path()), $file->name(), $file->extension(), - $file->page() + $file->page(), ))); } diff --git a/src/Support/helpers.php b/src/Support/helpers.php index 456958ca..7180720d 100644 --- a/src/Support/helpers.php +++ b/src/Support/helpers.php @@ -123,7 +123,7 @@ function dd(...$args) (new VarDumper())->dump($x); } - die(1); + exit(1); } } @@ -131,7 +131,7 @@ function inline($assetPath) { preg_match('/^\/assets\/build\/(css|js)\/.*\.(css|js)/', $assetPath, $matches); - if (!count($matches)) { + if (! count($matches)) { throw new InvalidArgumentException("Given asset path is not valid: {$assetPath}"); } diff --git a/src/View/BladeCompiler.php b/src/View/BladeCompiler.php index b80dd3ae..54a970a1 100644 --- a/src/View/BladeCompiler.php +++ b/src/View/BladeCompiler.php @@ -3,14 +3,14 @@ namespace TightenCo\Jigsaw\View; use Illuminate\View\Compilers\BladeCompiler as BaseBladeCompiler; -use TightenCo\Jigsaw\View\ComponentTagCompiler; class BladeCompiler extends BaseBladeCompiler { /** * Compile the component tags. * - * @param string $value + * @param string $value + * * @return string */ protected function compileComponentTags($value) @@ -20,7 +20,7 @@ protected function compileComponentTags($value) } return (new ComponentTagCompiler( - $this->classComponentAliases, $this->classComponentNamespaces, $this + $this->classComponentAliases, $this->classComponentNamespaces, $this, ))->compile($value); } } diff --git a/tests/AtSymbolInMarkdownTest.php b/tests/AtSymbolInMarkdownTest.php index 077c87af..7c452f6d 100644 --- a/tests/AtSymbolInMarkdownTest.php +++ b/tests/AtSymbolInMarkdownTest.php @@ -20,7 +20,7 @@ public function mailto_link_in_markdown_is_parsed_and_obfuscated() $this->assertEquals( '', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -40,7 +40,7 @@ public function mailto_link_in_blade_markdown_is_parsed() $this->assertEquals( '', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -54,13 +54,13 @@ public function at_symbol_after_closing_bracket_is_unchanged_in_markdown() 'master.blade.php' => "
@yield('content')
", ], 'test.md' => $this->getYamlHeader() . - "

@include('foo')

" + "

@include('foo')

", ]); $this->buildSite($files); $this->assertEquals( "

@include('foo')

", - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -74,13 +74,13 @@ public function double_at_symbol_in_fenced_code_block_is_parsed_to_single_at_sym 'master.blade.php' => "
@yield('content')
", ], 'test.blade.md' => $this->getYamlHeader() . - "```\n@@if(true)

Foo

@@endif\n```" + "```\n@@if(true)

Foo

@@endif\n```", ]); $this->buildSite($files); $this->assertEquals( '
@if(true)<h1>Foo</h1>@endif
', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -94,13 +94,13 @@ public function double_at_symbol_in_inline_code_block_is_parsed_to_single_at_sym 'master.blade.php' => "
@yield('content')
", ], 'test.blade.md' => $this->getYamlHeader() . - "`@@if(true)

Foo

@@endif`" + '`@@if(true)

Foo

@@endif`', ]); $this->buildSite($files); $this->assertEquals( '

@if(true)<h1>Foo</h1>@endif

', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } diff --git a/tests/BladeComponentTest.php b/tests/BladeComponentTest.php index 798d4fb9..3e79cbe8 100644 --- a/tests/BladeComponentTest.php +++ b/tests/BladeComponentTest.php @@ -4,7 +4,6 @@ use Illuminate\Container\Container; use Illuminate\View\Component; -use Illuminate\View\View; use org\bovigo\vfs\vfsStream; class BladeComponentTest extends TestCase @@ -41,8 +40,8 @@ public function can_include_blade_component_with_at_syntax() "

This is the component

\n" . "

Named title slot: Title test

\n" . "

Default content

\n" . - "", - $built + '', + $built, ); } @@ -64,7 +63,7 @@ public function can_include_blade_component_with_x_tag_syntax_using_underscore_c $this->assertEquals( '

Hello

The message
', - $built + $built, ); } @@ -90,7 +89,7 @@ public function can_include_blade_component_with_x_tag_syntax_using_aliased_comp $this->assertEquals( '

Hello

The message
', - $built + $built, ); } @@ -113,7 +112,7 @@ public function can_include_blade_component_with_x_tag_syntax_using_aliased_comp $this->assertEquals( '

Hello

The message
', - $built + $built, ); } @@ -136,7 +135,7 @@ class_alias('Tests\InlineAlertComponent', 'Components\InlineClassComponent'); $this->assertEquals( '

Hello

The message
', - $built + $built, ); } @@ -162,7 +161,7 @@ class_alias('Tests\\AlertComponent', 'Components\\ClassComponent'); $this->assertEquals( '

Hello

The message
', - $built + $built, ); } } diff --git a/tests/CollectionItemTest.php b/tests/CollectionItemTest.php index 4820b361..a2a39040 100644 --- a/tests/CollectionItemTest.php +++ b/tests/CollectionItemTest.php @@ -25,11 +25,11 @@ public function collection_item_contents_are_returned_when_item_is_referenced_as $this->assertEquals( $files->getChild('build/test_get_content.html')->getContent(), - $files->getChild('build/test_to_string.html')->getContent() + $files->getChild('build/test_to_string.html')->getContent(), ); $this->assertEquals( '

Collection Item Content

', - $this->clean($files->getChild('build/test_to_string.html')->getContent()) + $this->clean($files->getChild('build/test_to_string.html')->getContent()), ); } @@ -38,33 +38,32 @@ public function collection_item_contents_are_returned_when_item_is_referenced_as */ public function collection_item_can_be_filtered() { - $config = collect(['collections' => - [ + $config = collect(['collections' => [ 'collection' => [ 'path' => 'collection/{filename}', 'filter' => function ($item) { return $item->published; - } - ] - ] + }, + ], + ], ]); $builtHeader = implode("\n", [ '---', 'extends: _layouts.collection_item', 'published: true', 'section: content', - '---' + '---', ]); $filteredHeader = implode("\n", [ '---', 'extends: _layouts.collection_item', 'published: false', 'section: content', - '---' + '---', ]); $files = $this->setupSource([ '_layouts' => [ - 'collection_item.blade.php' => '@section(\'content\') @endsection' + 'collection_item.blade.php' => '@section(\'content\') @endsection', ], '_collection' => [ 'item.md' => implode("\n", [$builtHeader, '### Collection Item Content']), @@ -86,15 +85,14 @@ public function collection_item_can_be_filtered() */ public function collection_item_can_be_mapped() { - $config = collect(['collections' => - [ + $config = collect(['collections' => [ 'collection' => [ 'path' => 'collection/{filename}', 'map' => function ($item) { return MappedItem::fromItem($item); - } - ] - ] + }, + ], + ], ]); $itemHeader = implode("\n", [ '---', @@ -118,7 +116,7 @@ public function collection_item_can_be_mapped() $this->assertEquals( '111-222', - $this->clean($files->getChild('build/collection/item.html')->getContent()) + $this->clean($files->getChild('build/collection/item.html')->getContent()), ); } @@ -141,7 +139,7 @@ public function collection_item_page_metadata_contains_path() $this->assertEquals( '/collection/page', - $this->clean($files->getChild('build/collection/page/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page/index.html')->getContent()), ); } @@ -166,7 +164,7 @@ public function collection_item_page_metadata_contains_relative_path() $this->assertEquals( 'nested', - $this->clean($files->getChild('build/collection/page/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page/index.html')->getContent()), ); } @@ -189,7 +187,7 @@ public function collection_item_page_metadata_contains_extension() $this->assertEquals( 'blade.php', - $this->clean($files->getChild('build/collection/page/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page/index.html')->getContent()), ); } @@ -213,11 +211,11 @@ public function collection_item_page_metadata_contains_collection_name() $this->assertEquals( 'collection', - $this->clean($files->getChild('build/collection/page1/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page1/index.html')->getContent()), ); $this->assertEquals( 'collection', - $this->clean($files->getChild('build/collection/page2/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page2/index.html')->getContent()), ); } @@ -240,7 +238,7 @@ public function collection_item_page_metadata_contains_source_path() $this->assertEquals( 'vfs://virtual/source/_collection', - $this->clean($files->getChild('build/collection/page/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page/index.html')->getContent()), ); } @@ -263,7 +261,7 @@ public function collection_item_page_metadata_contains_modified_time() $this->assertEquals( $files->getChild('build/collection/page/index.html')->filemtime(), - $this->clean($files->getChild('build/collection/page/index.html')->getContent()) + $this->clean($files->getChild('build/collection/page/index.html')->getContent()), ); } } diff --git a/tests/ConfigVariableTest.php b/tests/ConfigVariableTest.php index 5d223037..79a61e08 100644 --- a/tests/ConfigVariableTest.php +++ b/tests/ConfigVariableTest.php @@ -18,7 +18,7 @@ public function config_variables_are_replaced_with_values_in_blade_templates() $this->assertEquals( '
value
', - $files->getChild('build/variable-test.html')->getContent() + $files->getChild('build/variable-test.html')->getContent(), ); } @@ -37,7 +37,7 @@ public function config_variables_are_overridden_by_local_variables_in_blade_temp $this->assertEquals( '
local
', - $files->getChild('build/variable-test.html')->getContent() + $files->getChild('build/variable-test.html')->getContent(), ); } } diff --git a/tests/CustomCommandTest.php b/tests/CustomCommandTest.php index b8d71afa..a64a46b5 100644 --- a/tests/CustomCommandTest.php +++ b/tests/CustomCommandTest.php @@ -6,7 +6,6 @@ use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use TightenCo\Jigsaw\Console\Command; -use TightenCo\Jigsaw\Jigsaw; class CustomCommandTest extends TestCase { @@ -26,9 +25,10 @@ public function custom_command_with_no_arguments() } } -class CustomCommand extends Command { +class CustomCommand extends Command +{ protected function fire() { - $this->console->info("Command Tested"); + $this->console->info('Command Tested'); } } diff --git a/tests/EventsTest.php b/tests/EventsTest.php index 18bf7ac5..2879f206 100644 --- a/tests/EventsTest.php +++ b/tests/EventsTest.php @@ -65,7 +65,8 @@ public function __construct() $this->object = (object) []; } - public function __invoke($jigsaw) { + public function __invoke($jigsaw) + { $jigsaw->setConfig('variable_a', 'Set from invokable'); } }); @@ -241,7 +242,7 @@ public function collection_items_created_in_before_build_event_listener_are_outp $this->assertCount(1, $files->getChild('build/posts')->getChildren()); $this->assertEquals( '

Content for post #1

', - $this->clean($files->getChild('build/posts/post-1.html')->getContent()) + $this->clean($files->getChild('build/posts/post-1.html')->getContent()), ); } @@ -277,11 +278,11 @@ public function collection_items_added_in_before_build_event_listener_are_output $this->assertCount(2, $files->getChild('build/posts')->getChildren()); $this->assertEquals( '

Content for post #1

', - $this->clean($files->getChild('build/posts/post-1.html')->getContent()) + $this->clean($files->getChild('build/posts/post-1.html')->getContent()), ); $this->assertEquals( '

Content for post #2

', - $this->clean($files->getChild('build/posts/post-2.html')->getContent()) + $this->clean($files->getChild('build/posts/post-2.html')->getContent()), ); } diff --git a/tests/FilesystemTest.php b/tests/FilesystemTest.php index 8c06fe8f..426fa2da 100644 --- a/tests/FilesystemTest.php +++ b/tests/FilesystemTest.php @@ -7,7 +7,7 @@ class FilesystemTest extends TestCase { - const TEST_FILES = [ + public const TEST_FILES = [ '.dotfile' => '', 'file-1.md' => '', 'file-2.md' => '', @@ -49,7 +49,7 @@ public function DS_Store_is_always_ignored_when_retrieving_all_files_and_directo $files = collect( $this->app->make(Filesystem::class) - ->filesAndDirectories($vfs->url()) + ->filesAndDirectories($vfs->url()), )->map(function ($file) { return $file->getRelativePathName(); }); @@ -256,7 +256,7 @@ protected function getFilesMatching($match) { return collect( $this->app->make(Filesystem::class) - ->filesAndDirectories($this->setupFiles()->url(), $match) + ->filesAndDirectories($this->setupFiles()->url(), $match), )->map(function ($file) { return $file->getRelativePathName(); }); @@ -266,7 +266,7 @@ protected function getFilesExcept($ignore) { return collect( $this->app->make(Filesystem::class) - ->filesAndDirectories($this->setupFiles()->url(), null, $ignore) + ->filesAndDirectories($this->setupFiles()->url(), null, $ignore), )->map(function ($file) { return $file->getRelativePathName(); }); diff --git a/tests/MarkdownExtraTest.php b/tests/MarkdownExtraTest.php index 0133dfb9..4779cfb7 100644 --- a/tests/MarkdownExtraTest.php +++ b/tests/MarkdownExtraTest.php @@ -18,8 +18,8 @@ public function parse_markdown_inside_html_blocks() $this->buildSite($files); $this->assertEquals( - "

This is true markdown text.

", - $this->clean($files->getChild('build/test.html')->getContent()) + '

This is true markdown text.

', + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -38,7 +38,7 @@ public function can_specify_id_in_markdown() $this->assertEquals( '

Testing ID

', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -57,7 +57,7 @@ public function can_specify_internal_anchor_links_in_markdown() $this->assertEquals( '', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -76,7 +76,7 @@ public function can_specify_class_name_in_markdown() $this->assertEquals( '

Testing class

', - $this->clean($files->getChild('build/test.html')->getContent()) + $this->clean($files->getChild('build/test.html')->getContent()), ); } @@ -102,23 +102,23 @@ public function correctly_parse_single_line_html_markup_in_markdown_file() $this->buildSite($files); $this->assertEquals( - "

Header 1

Header 2

", - $this->clean($files->getChild('build/multi-line.html')->getContent()) + '

Header 1

Header 2

', + $this->clean($files->getChild('build/multi-line.html')->getContent()), ); $this->assertEquals( - "

Header 1

Header 2

", - $this->clean($files->getChild('build/single-line.html')->getContent()) + '

Header 1

Header 2

', + $this->clean($files->getChild('build/single-line.html')->getContent()), ); $this->assertEquals( '

Header 1

Header 2

', - $this->clean($files->getChild('build/single-line-with-space.html')->getContent()) + $this->clean($files->getChild('build/single-line-with-space.html')->getContent()), ); $this->assertEquals( - "

Contact Method: email

Test

Some italic text.

", - $this->clean($files->getChild('build/nested.html')->getContent()) + '

Contact Method: email

Test

Some italic text.

', + $this->clean($files->getChild('build/nested.html')->getContent()), ); } diff --git a/tests/PageDataBindingTest.php b/tests/PageDataBindingTest.php index 8a792aea..138feeca 100644 --- a/tests/PageDataBindingTest.php +++ b/tests/PageDataBindingTest.php @@ -3,8 +3,8 @@ namespace Tests; use Illuminate\Container\Container; -use Illuminate\View\Component; use Illuminate\Support\Str; +use Illuminate\View\Component; use org\bovigo\vfs\vfsStream; use TightenCo\Jigsaw\PageData; diff --git a/tests/PaginationTest.php b/tests/PaginationTest.php index b8b74038..531e7cd4 100644 --- a/tests/PaginationTest.php +++ b/tests/PaginationTest.php @@ -37,15 +37,15 @@ public function blade_template_file_can_be_paginated() $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -82,15 +82,15 @@ public function blade_markdown_template_file_can_be_paginated() $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -126,15 +126,15 @@ public function blade_template_file_pagination_perPage_setting_defaults_to_confi $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -170,15 +170,15 @@ public function blade_template_file_pagination_perPage_setting_defaults_to_confi $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -214,15 +214,15 @@ public function blade_template_file_pagination_perPage_setting_defaults_to_confi $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -259,15 +259,15 @@ public function blade_template_file_pagination_perPage_setting_overrides_config_ $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -304,15 +304,15 @@ public function blade_template_file_pagination_perPage_setting_overrides_config_ $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } @@ -349,15 +349,15 @@ public function blade_template_file_pagination_perPage_setting_overrides_config_ $this->assertEquals( 'post1 post2', - $this->clean($files->getChild('build/blog/index.html')->getContent()) + $this->clean($files->getChild('build/blog/index.html')->getContent()), ); $this->assertEquals( 'post3 post4', - $this->clean($files->getChild('build/blog/2/index.html')->getContent()) + $this->clean($files->getChild('build/blog/2/index.html')->getContent()), ); $this->assertEquals( 'post5', - $this->clean($files->getChild('build/blog/3/index.html')->getContent()) + $this->clean($files->getChild('build/blog/3/index.html')->getContent()), ); } diff --git a/tests/PermalinkTest.php b/tests/PermalinkTest.php index 9797419e..c3a61ae1 100644 --- a/tests/PermalinkTest.php +++ b/tests/PermalinkTest.php @@ -18,7 +18,7 @@ public function markdown_file_with_permalink_is_built_at_permalink_destination_w $this->assertEquals( '

Permalink file

', - $this->clean($files->getChild('build/permalink.html')->getContent()) + $this->clean($files->getChild('build/permalink.html')->getContent()), ); } @@ -36,7 +36,7 @@ public function markdown_file_with_permalink_is_built_at_permalink_destination_w $this->assertEquals( '

Permalink file

', - $this->clean($files->getChild('build/permalink.html')->getContent()) + $this->clean($files->getChild('build/permalink.html')->getContent()), ); } @@ -54,7 +54,7 @@ public function markdown_file_with_nested_permalink_is_built_at_permalink_destin $this->assertEquals( '

Permalink file

', - $this->clean($files->getChild('build/nested/permalink.html')->getContent()) + $this->clean($files->getChild('build/nested/permalink.html')->getContent()), ); } @@ -72,7 +72,7 @@ public function markdown_file_with_nested_permalink_is_built_at_permalink_destin $this->assertEquals( '

Permalink file

', - $this->clean($files->getChild('build/nested/permalink.html')->getContent()) + $this->clean($files->getChild('build/nested/permalink.html')->getContent()), ); } @@ -90,7 +90,7 @@ public function permalink_can_contain_leading_slash() $this->assertEquals( '

Permalink file

', - $this->clean($files->getChild('build/permalink.html')->getContent()) + $this->clean($files->getChild('build/permalink.html')->getContent()), ); } diff --git a/tests/RemoteCollectionsTest.php b/tests/RemoteCollectionsTest.php index c7e4eff5..3a5b24a9 100644 --- a/tests/RemoteCollectionsTest.php +++ b/tests/RemoteCollectionsTest.php @@ -41,11 +41,11 @@ public function collection_items_are_created_from_files_in_a_collection_director $this->assertCount(2, $siteData->collection); $this->assertEquals( '

Test markdown file #1

', - $this->clean($siteData->collection->file_1->getContent()) + $this->clean($siteData->collection->file_1->getContent()), ); $this->assertEquals( '

Test markdown file #2

', - $this->clean($siteData->collection->file_2->getContent()) + $this->clean($siteData->collection->file_2->getContent()), ); } @@ -91,11 +91,11 @@ public function output_files_are_built_from_files_in_a_collection_directory() $this->assertCount(2, $files->getChild('build/collection')->getChildren()); $this->assertEquals( '

File 1 Content

', - $this->clean($files->getChild('build/collection/file-1.html')->getContent()) + $this->clean($files->getChild('build/collection/file-1.html')->getContent()), ); $this->assertEquals( '

File 2 Content

', - $this->clean($files->getChild('build/collection/file-2.html')->getContent()) + $this->clean($files->getChild('build/collection/file-2.html')->getContent()), ); } @@ -126,7 +126,7 @@ public function output_files_are_built_from_items_key_in_config() $this->assertCount(1, $files->getChild('build/test')->getChildren()); $this->assertEquals( '

item content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -162,11 +162,11 @@ public function output_files_are_built_from_items_key_in_config_and_from_files_i $this->assertCount(2, $files->getChild('build/test')->getChildren()); $this->assertEquals( '

config content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); $this->assertEquals( '

file content

', - $this->clean($files->getChild('build/test/file-1.html')->getContent()) + $this->clean($files->getChild('build/test/file-1.html')->getContent()), ); } @@ -251,7 +251,7 @@ public function items_key_in_config_can_return_an_illuminate_collection() $this->assertCount(1, $files->getChild('build/test')->getChildren()); $this->assertEquals( '

item content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -281,7 +281,7 @@ public function value_of_content_key_in_item_array_is_parsed_as_markdown() $this->assertEquals( '

item content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -312,7 +312,7 @@ public function page_variables_are_created_from_keys_in_item_array() $this->assertEquals( '
page variable
', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -342,7 +342,7 @@ public function page_variables_are_optional_in_item_array() $this->assertEquals( '

item content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -368,7 +368,7 @@ public function value_of_string_item_is_parsed_as_markdown_content() $this->assertEquals( '

item content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -400,11 +400,11 @@ public function strings_and_arrays_can_be_mixed_in_items_key_in_config() $this->assertEquals( '

item 1 content

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); $this->assertEquals( '

item 2 content

', - $this->clean($files->getChild('build/test/test-2.html')->getContent()) + $this->clean($files->getChild('build/test/test-2.html')->getContent()), ); } @@ -525,11 +525,11 @@ public function items_key_in_config_can_be_a_function_that_returns_an_array() $this->assertEquals( '

item 1

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); $this->assertEquals( '

item 2

', - $this->clean($files->getChild('build/test/test-2.html')->getContent()) + $this->clean($files->getChild('build/test/test-2.html')->getContent()), ); } @@ -560,7 +560,7 @@ public function items_function_can_access_other_config_variables() $this->assertEquals( '

https://example.com/api

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -591,11 +591,11 @@ public function items_key_in_config_can_be_a_function_that_returns_a_collection( $this->assertEquals( '

item 1

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); $this->assertEquals( '

item 2

', - $this->clean($files->getChild('build/test/test-2.html')->getContent()) + $this->clean($files->getChild('build/test/test-2.html')->getContent()), ); } @@ -628,7 +628,7 @@ public function items_key_in_config_can_fetch_content_from_a_remote_api() $content = json_decode(file_get_contents('https://jsonplaceholder.typicode.com/posts/1'))->body; $this->assertEquals( $this->clean('

' . $content . '

'), - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } @@ -654,7 +654,7 @@ public function blade_directives_in_remote_content_get_parsed() $this->assertEquals( '

Hey there

', - $this->clean($files->getChild('build/test/test-1.html')->getContent()) + $this->clean($files->getChild('build/test/test-1.html')->getContent()), ); } } diff --git a/tests/ScaffoldTest.php b/tests/ScaffoldTest.php index 1d230de1..a192c2d7 100644 --- a/tests/ScaffoldTest.php +++ b/tests/ScaffoldTest.php @@ -7,7 +7,7 @@ class ScaffoldTest extends TestCase { - const EXISTING_FILES = [ + public const EXISTING_FILES = [ '.gitignore' => '', 'bootstrap.php' => '', 'config.php' => '', @@ -27,7 +27,7 @@ public function can_archive_existing_files_and_directories() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['archived' => []] + ['archived' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -64,7 +64,7 @@ public function will_erase_contents_of_archived_directory_if_it_already_exists_w { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['archived' => ['old-file.md' => '']] + ['archived' => ['old-file.md' => '']], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -83,7 +83,7 @@ public function will_ignore_archived_directory_when_archiving_site() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['archived' => []] + ['archived' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -100,7 +100,7 @@ public function will_ignore_vendor_directory_when_archiving_site() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['vendor' => []] + ['vendor' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -117,7 +117,7 @@ public function will_ignore_node_modules_directory_when_archiving_site() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['node_modules' => []] + ['node_modules' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -149,7 +149,7 @@ public function will_ignore_archived_directory_when_deleting_site() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['archived' => []] + ['archived' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -165,7 +165,7 @@ public function will_ignore_vendor_directory_when_deleting_site() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['vendor' => []] + ['vendor' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); @@ -181,7 +181,7 @@ public function will_ignore_node_modules_directory_when_deleting_site() { $vfs = vfsStream::setup('virtual', null, array_merge( self::EXISTING_FILES, - ['node_modules' => []] + ['node_modules' => []], )); $scaffold = $this->app->make(BasicScaffoldBuilder::class)->setBase($vfs->url()); diff --git a/tests/SiteBuilderTest.php b/tests/SiteBuilderTest.php index 276385ab..cdefe494 100644 --- a/tests/SiteBuilderTest.php +++ b/tests/SiteBuilderTest.php @@ -50,14 +50,12 @@ public function existing_files_in_destination_directory_are_replaced_when_buildi */ public function page_metadata_contains_path() { - $files = $this->setupSource(['nested' => - ['page.blade.php' => '{{ $page->getPath() }}'], - ]); + $files = $this->setupSource(['nested' => ['page.blade.php' => '{{ $page->getPath() }}']]); $this->buildSite($files, [], $pretty = true); $this->assertEquals( '/nested/page', - $this->clean($files->getChild('build/nested/page/index.html')->getContent()) + $this->clean($files->getChild('build/nested/page/index.html')->getContent()), ); } @@ -66,14 +64,12 @@ public function page_metadata_contains_path() */ public function page_metadata_contains_relative_path() { - $files = $this->setupSource(['nested' => - ['page.blade.php' => '{{ $page->getRelativePath() }}'], - ]); + $files = $this->setupSource(['nested' => ['page.blade.php' => '{{ $page->getRelativePath() }}']]); $this->buildSite($files, [], $pretty = true); $this->assertEquals( 'nested', - $this->clean($files->getChild('build/nested/page/index.html')->getContent()) + $this->clean($files->getChild('build/nested/page/index.html')->getContent()), ); } @@ -89,7 +85,7 @@ public function page_metadata_contains_url() $this->assertEquals( 'foo.com/page', - $this->clean($files->getChild('build/page/index.html')->getContent()) + $this->clean($files->getChild('build/page/index.html')->getContent()), ); } @@ -103,7 +99,7 @@ public function page_metadata_contains_source_file_name() $this->assertEquals( 'page', - $this->clean($files->getChild('build/page/index.html')->getContent()) + $this->clean($files->getChild('build/page/index.html')->getContent()), ); } @@ -117,7 +113,7 @@ public function page_metadata_contains_source_file_extension() $this->assertEquals( 'blade.php', - $this->clean($files->getChild('build/page/index.html')->getContent()) + $this->clean($files->getChild('build/page/index.html')->getContent()), ); } @@ -131,7 +127,7 @@ public function page_metadata_contains_source_file_modified_time() $this->assertEquals( $files->getChild('build/page/index.html')->filemtime(), - $this->clean($files->getChild('build/page/index.html')->getContent()) + $this->clean($files->getChild('build/page/index.html')->getContent()), ); } @@ -153,7 +149,7 @@ public function can_get_output_paths_after_building_site() '/page1', '/nested/page2', ], - $jigsaw->getOutputPaths()->toArray() + $jigsaw->getOutputPaths()->toArray(), ); } @@ -173,7 +169,7 @@ public function can_get_collection_of_page_info_after_building_site() $source1 = $jigsaw->getPages()->get('/page1'); $this->assertEquals( $files->getChild('build/page1/index.html')->filemtime(), - $source1->getModifiedTime() + $source1->getModifiedTime(), ); $this->assertEquals('page1', $source1->getFilename()); $this->assertEquals('/page1', $source1->getPath()); @@ -182,7 +178,7 @@ public function can_get_collection_of_page_info_after_building_site() $source2 = $jigsaw->getPages()->get('/nested/page2'); $this->assertEquals( $files->getChild('build/nested/page2/index.html')->filemtime(), - $source2->getModifiedTime() + $source2->getModifiedTime(), ); $this->assertEquals('page2', $source2->getFilename()); $this->assertEquals('/nested/page2', $source2->getPath()); diff --git a/tests/TestCase.php b/tests/TestCase.php index ce25353c..2f051bf0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -97,7 +97,7 @@ public function buildSite($vfs, $config = [], $pretty = false, $viewPath = '/sou public function clean($output) { - return str_replace("\n", "", $output); + return str_replace("\n", '', $output); } protected function fixDirectorySlashes(string $path): string diff --git a/tests/ViewPathTest.php b/tests/ViewPathTest.php index dd925c50..8e612e32 100644 --- a/tests/ViewPathTest.php +++ b/tests/ViewPathTest.php @@ -34,7 +34,7 @@ public function can_load_views_from_custom_path()

Hello world!

HTML, - $files->getChild('build/page.html')->getContent() + $files->getChild('build/page.html')->getContent(), ); } } diff --git a/tests/ViewRendererTest.php b/tests/ViewRendererTest.php index f1571687..b06477e6 100644 --- a/tests/ViewRendererTest.php +++ b/tests/ViewRendererTest.php @@ -20,12 +20,12 @@ public function it_registers_view_hint_paths() $mock->shouldReceive('addExtension'); new ViewRenderer($mock, Mockery::mock(BladeCompiler::class), collect([ 'viewHintPaths' => [ - 'view::hint' => 'path' - ] + 'view::hint' => 'path', + ], ])); $this->addToAssertionCount( - Mockery::getContainer()->mockery_getExpectationCount() + Mockery::getContainer()->mockery_getExpectationCount(), ); } @@ -41,7 +41,7 @@ public function it_does_not_register_view_hint_paths_if_not_specified_in_config( new ViewRenderer($mock, Mockery::mock(BladeCompiler::class)); $this->addToAssertionCount( - Mockery::getContainer()->mockery_getExpectationCount() + Mockery::getContainer()->mockery_getExpectationCount(), ); } @@ -55,11 +55,11 @@ public function it_does_not_register_view_hint_paths_if_empty_in_config() $mock->shouldNotReceive('addNamespace')->with('view::hint', 'path'); $mock->shouldReceive('addExtension'); new ViewRenderer($mock, Mockery::mock(BladeCompiler::class), collect([ - 'viewHintPaths' => [] + 'viewHintPaths' => [], ])); $this->addToAssertionCount( - Mockery::getContainer()->mockery_getExpectationCount() + Mockery::getContainer()->mockery_getExpectationCount(), ); } } From 6199caf07b74d76ee9a88100991b92fb16fd799d Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:54:28 -0400 Subject: [PATCH 07/15] Update rules --- .php-cs-fixer.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 55ece8f1..ea7a23df 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -29,6 +29,9 @@ ], // 'declare_strict_types' => true, 'get_class_to_class_keyword' => true, + 'global_namespace_import' => [ + 'import_classes' => true, + ], // 'no_extra_blank_lines' => ['tokens' => ['extra', 'use']], 'new_with_braces' => false, 'no_empty_comment' => false, From 12148101ebd2a945d581bf17a7d3c7ed139250cb Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:55:35 -0400 Subject: [PATCH 08/15] Format --- src/PageVariable.php | 6 +++--- src/View/ComponentTagCompiler.php | 8 ++------ stubs/site/bootstrap.php | 4 ++-- tests/CustomScaffoldInstallerTest.php | 12 ++++++------ tests/DefaultScaffoldInstallerTest.php | 4 ++-- tests/PresetScaffoldBuilderTest.php | 15 ++++++++------- 6 files changed, 23 insertions(+), 26 deletions(-) diff --git a/src/PageVariable.php b/src/PageVariable.php index ca816cca..cef23a43 100644 --- a/src/PageVariable.php +++ b/src/PageVariable.php @@ -2,6 +2,7 @@ namespace TightenCo\Jigsaw; +use Exception; use Illuminate\Support\Str; class PageVariable extends IterableObject @@ -17,15 +18,14 @@ public function __call($method, $args) if (! $helper && Str::startsWith($method, 'get')) { return $this->_meta->get(Str::camel(substr($method, 3)), function () use ($method) { - throw new \Exception($this->missingHelperError($method)); + throw new Exception($this->missingHelperError($method)); }); } if (is_callable($helper)) { return $helper->__invoke($this, ...$args); - } else { - throw new \Exception($this->missingHelperError($method)); } + throw new Exception($this->missingHelperError($method)); } public function getPath($key = null) diff --git a/src/View/ComponentTagCompiler.php b/src/View/ComponentTagCompiler.php index 43b86518..cdc27af7 100644 --- a/src/View/ComponentTagCompiler.php +++ b/src/View/ComponentTagCompiler.php @@ -31,9 +31,7 @@ public function componentClass(string $component) return $alias; } - throw new InvalidArgumentException( - "Unable to locate class or view [{$alias}] for component [{$component}]." - ); + throw new InvalidArgumentException("Unable to locate class or view [{$alias}] for component [{$component}]."); } if ($class = $this->findClassByComponent($component)) { @@ -70,9 +68,7 @@ public function componentClass(string $component) return $guess; } - throw new InvalidArgumentException( - "Unable to locate a class or view for component [{$component}]." - ); + throw new InvalidArgumentException("Unable to locate a class or view for component [{$component}]."); } /** diff --git a/stubs/site/bootstrap.php b/stubs/site/bootstrap.php index 52624079..832d78dd 100644 --- a/stubs/site/bootstrap.php +++ b/stubs/site/bootstrap.php @@ -2,8 +2,8 @@ use TightenCo\Jigsaw\Jigsaw; -/** @var $container \Illuminate\Container\Container */ -/** @var $events \TightenCo\Jigsaw\Events\EventBus */ +/** @var \Illuminate\Container\Container $container */ +/** @var \TightenCo\Jigsaw\Events\EventBus $events */ /** * You can run custom code at different stages of the build process by diff --git a/tests/CustomScaffoldInstallerTest.php b/tests/CustomScaffoldInstallerTest.php index ac9a6310..c1d5eea4 100644 --- a/tests/CustomScaffoldInstallerTest.php +++ b/tests/CustomScaffoldInstallerTest.php @@ -353,7 +353,7 @@ public function original_composer_json_is_not_deleted() $this->assertNotNull($vfs->getChild('composer.json')); $this->assertEquals( $old_composer, - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } @@ -395,7 +395,7 @@ public function original_composer_json_is_merged_with_new_composer_json_after_co 'other/package' => '2.0', ], ], - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } @@ -447,7 +447,7 @@ public function composer_json_files_are_merged_when_copying_multiple_times() 'another/package' => '3.0', ], ], - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } @@ -474,7 +474,7 @@ public function empty_composer_json_is_created_if_it_was_not_present_before_pres [ 'require' => [], ], - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } @@ -511,7 +511,7 @@ public function installer_can_ask_for_user_input_with_choices() ->ask( 'What theme would you like to use?', ['l' => 'light', 'd' => 'dark'], - $default = 'l' + $default = 'l', ); $console->shouldHaveReceived('ask') @@ -519,7 +519,7 @@ public function installer_can_ask_for_user_input_with_choices() 'What theme would you like to use?', ['l' => 'light', 'd' => 'dark'], 'l', - null + null, ); } diff --git a/tests/DefaultScaffoldInstallerTest.php b/tests/DefaultScaffoldInstallerTest.php index 5d3d55c0..599e7d58 100644 --- a/tests/DefaultScaffoldInstallerTest.php +++ b/tests/DefaultScaffoldInstallerTest.php @@ -160,7 +160,7 @@ public function installer_overwrites_base_files_of_same_name_when_copying_preset $this->assertEquals( 'new config file from preset', - $vfs->getChild('config.php')->getContent() + $vfs->getChild('config.php')->getContent(), ); } @@ -497,7 +497,7 @@ public function empty_composer_json_is_created_if_it_was_not_present_before_pres [ 'require' => [], ], - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } } diff --git a/tests/PresetScaffoldBuilderTest.php b/tests/PresetScaffoldBuilderTest.php index 8d50f3e7..06469d37 100644 --- a/tests/PresetScaffoldBuilderTest.php +++ b/tests/PresetScaffoldBuilderTest.php @@ -2,6 +2,7 @@ namespace Tests; +use Exception; use Mockery; use org\bovigo\vfs\vfsStream; use TightenCo\Jigsaw\Scaffold\CustomInstaller; @@ -33,7 +34,7 @@ public function named_preset_resolves_to_predefined_package_path() $this->assertEquals( $vfs->url() . $this->fixDirectorySlashes('/vendor/tightenco/jigsaw-blog-template'), - $preset->package->path + $preset->package->path, ); } @@ -56,7 +57,7 @@ public function named_preset_resolves_to_vendor_package_path_if_not_predefined() $preset->init('test/package'); - $this->assertEquals($vfs->url() . $this->fixDirectorySlashes('/vendor/' . 'test/package'), $preset->package->path); + $this->assertEquals($vfs->url() . $this->fixDirectorySlashes('/vendor/test/package'), $preset->package->path); } /** @@ -88,10 +89,10 @@ public function exception_is_thrown_if_package_is_missing_a_slash() try { $preset->init('test'); $this->fail('Exception not thrown'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertStringContainsString( "'test' is not a valid package name.", - $e->getMessage() + $e->getMessage(), ); } } @@ -119,7 +120,7 @@ public function exception_is_thrown_if_package_init_file_contains_errors() $preset->build(); $this->fail('Exception not thrown'); - } catch (\Exception $e) { + } catch (Exception $e) { $this->assertStringContainsString('contains errors', $e->getMessage()); } } @@ -246,7 +247,7 @@ public function jigsaw_package_dependency_is_restored_to_fresh_composer_dot_json 'tightenco/jigsaw' => '^1.2', ], ], - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } @@ -282,7 +283,7 @@ public function jigsaw__package_dependency_is_restored_to_fresh_composer_dot_jso 'tightenco/jigsaw' => '^1.2', ], ], - json_decode($vfs->getChild('composer.json')->getContent(), true) + json_decode($vfs->getChild('composer.json')->getContent(), true), ); } } From e129a805942917142afdba69885702a11b18ca3f Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 16:55:59 -0400 Subject: [PATCH 09/15] Update rules and format --- .php-cs-fixer.php | 2 +- src/IterableObject.php | 1 + src/PageVariable.php | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index ea7a23df..948922e9 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -22,7 +22,7 @@ 'blank_line_after_namespace' => true, 'blank_line_after_opening_tag' => true, 'blank_line_before_statement' => [ - 'statements' => ['return'], + 'statements' => ['return', 'throw'], ], 'concat_space' => [ 'spacing' => 'one', diff --git a/src/IterableObject.php b/src/IterableObject.php index b9c808e3..36f5d546 100644 --- a/src/IterableObject.php +++ b/src/IterableObject.php @@ -64,6 +64,7 @@ public function offsetGet($key): mixed { if (! isset($this->items[$key])) { $prefix = $this->_source ? 'Error in ' . $this->_source . ': ' : 'Error: '; + throw new Exception($prefix . "The key '$key' does not exist."); } diff --git a/src/PageVariable.php b/src/PageVariable.php index cef23a43..4f814eb6 100644 --- a/src/PageVariable.php +++ b/src/PageVariable.php @@ -25,6 +25,7 @@ public function __call($method, $args) if (is_callable($helper)) { return $helper->__invoke($this, ...$args); } + throw new Exception($this->missingHelperError($method)); } From 9f065ae824efb7c6cb586448a9e50233d87d5ca1 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 17:04:25 -0400 Subject: [PATCH 10/15] Update rules and format --- .php-cs-fixer.php | 4 +++- src/View/ComponentTagCompiler.php | 4 +--- stubs/site/bootstrap.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 948922e9..93d6c3e3 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -39,10 +39,12 @@ 'not_operator_with_successor_space' => true, 'php_unit_method_casing' => false, 'phpdoc_annotation_without_dot' => false, - 'phpdoc_order' => true, '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, diff --git a/src/View/ComponentTagCompiler.php b/src/View/ComponentTagCompiler.php index cdc27af7..b52538c8 100644 --- a/src/View/ComponentTagCompiler.php +++ b/src/View/ComponentTagCompiler.php @@ -13,10 +13,9 @@ class ComponentTagCompiler extends BaseComponentTagCompiler /** * Get the component class for a given component alias. * - * @param string $component * @return string * - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ public function componentClass(string $component) { @@ -74,7 +73,6 @@ public function componentClass(string $component) /** * Guess the class name for the given component. * - * @param string $component * @return string */ public function guessClassName(string $component) diff --git a/stubs/site/bootstrap.php b/stubs/site/bootstrap.php index 832d78dd..f603d4e2 100644 --- a/stubs/site/bootstrap.php +++ b/stubs/site/bootstrap.php @@ -5,7 +5,7 @@ /** @var \Illuminate\Container\Container $container */ /** @var \TightenCo\Jigsaw\Events\EventBus $events */ -/** +/* * You can run custom code at different stages of the build process by * listening to the 'beforeBuild', 'afterCollections', and 'afterBuild' events. * From e946ac5a5f3adb60e461ad4e16cda8931aab01f1 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 17:05:38 -0400 Subject: [PATCH 11/15] Ignore formatting commits when blaming --- .git-blame-ignore-revs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 3294f91d..e983fc06 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -3,3 +3,9 @@ # Rename SnapshotTest to SnapshotsTest 45b422424a03c24ad2aed0af2bd0648ba4eb4e17 + +# Format +ec8c6c07e290fa3c85fd7a1975d1bee0f0d417b9 + +# Format +12148101ebd2a945d581bf17a7d3c7ed139250cb From d56c7ca4b2a8e1c713e8ecbac1bebe9110a4cf99 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Fri, 4 Nov 2022 17:10:55 -0400 Subject: [PATCH 12/15] Wip --- .php-cs-fixer.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 93d6c3e3..2e71fee2 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -16,7 +16,7 @@ ], 'binary_operator_spaces' => [ 'operators' => [ - '|' => 'single_space' // Doesn't apply to union types + '|' => 'single_space', // Doesn't apply to union types ], ], 'blank_line_after_namespace' => true, @@ -27,12 +27,10 @@ 'concat_space' => [ 'spacing' => 'one', ], - // 'declare_strict_types' => true, 'get_class_to_class_keyword' => true, 'global_namespace_import' => [ 'import_classes' => true, ], - // 'no_extra_blank_lines' => ['tokens' => ['extra', 'use']], 'new_with_braces' => false, 'no_empty_comment' => false, 'no_useless_else' => true, From 380103f85ea32e6b54d179131ff199bae746c506 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Sat, 5 Nov 2022 00:18:37 -0400 Subject: [PATCH 13/15] Add workflow to format automatically --- .github/workflows/format.yml | 34 ++++++++++++++++++++++++++++++++++ .github/workflows/test.yml | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/format.yml diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml new file mode 100644 index 00000000..85e56884 --- /dev/null +++ b/.github/workflows/format.yml @@ -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 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 148502cc..42e1031c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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' }} From 98e470c26e6d065d281da758bfe3b84b328e31c6 Mon Sep 17 00:00:00 2001 From: Jacob Baker-Kretzmar Date: Sat, 5 Nov 2022 00:23:21 -0400 Subject: [PATCH 14/15] Wip --- .php-cs-fixer.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 2e71fee2..a24d0b40 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -1,12 +1,7 @@ setFinder( - PhpCsFixer\Finder::create() - ->in(__DIR__) - ->exclude(['vendor', 'tests/snapshots']) - ->name('*.php') - ) + ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)->exclude('tests/snapshots')) ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, @@ -41,7 +36,9 @@ 'ignored_tags' => ['var'], ], 'phpdoc_separation' => [ - 'groups' => [['test', 'group', 'dataProvider', 'doesNotPerformAssertions']] + 'groups' => [ + ['test', 'group', 'dataProvider', 'doesNotPerformAssertions'], + ], ], 'phpdoc_var_annotation_correct_order' => true, 'trailing_comma_in_multiline' => [ From 308d7a38be2c1ece1b75bfd4a5cf8421e4ed313f Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 11 Nov 2022 21:29:42 +0000 Subject: [PATCH 15/15] Format 1) src/Support/ServiceProvider.php (braces) 2) src/Container.php (increment_style, trailing_comma_in_multiline) --- src/Container.php | 4 ++-- src/Support/ServiceProvider.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Container.php b/src/Container.php index 1e18dbc1..6cd6e3d1 100644 --- a/src/Container.php +++ b/src/Container.php @@ -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 => []], )); } @@ -147,7 +147,7 @@ private function fireAppCallbacks(array &$callbacks): void while ($index < count($callbacks)) { $callbacks[$index]($this); - $index++; + ++$index; } } diff --git a/src/Support/ServiceProvider.php b/src/Support/ServiceProvider.php index 16052f78..8e809b77 100644 --- a/src/Support/ServiceProvider.php +++ b/src/Support/ServiceProvider.php @@ -8,7 +8,8 @@ abstract class ServiceProvider { public function __construct( protected Container $app, - ) {} + ) { + } public function register(): void {