Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
<?php

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

if (!file_exists(__DIR__.'/src')) {
exit(0);
}

$finder = (new PhpCsFixer\Finder())
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;
$fileHeaderComment = <<<'EOF'
This file is part of the Symfony WebpackEncoreBundle package.

(c) Fabien Potencier <[email protected]>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF;

return (new PhpCsFixer\Config())
->setRules(array(
// @see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/pull/7777
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
->setRules([
'@PHP71Migration' => true,
'@PHPUnit75Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'@PHPUnit75Migration:risky' => true,
'protected_to_private' => false,
'semicolon_after_instruction' => false,
'header_comment' => [
'header' => <<<EOF
This file is part of the Symfony WebpackEncoreBundle package.
(c) Fabien Potencier <[email protected]>
For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.
EOF
]
))
'header_comment' => ['header' => $fileHeaderComment],
'trailing_comma_in_multiline' => ['elements' => ['arrays', 'match', 'parameters']],
])
->setRiskyAllowed(true)
->setFinder($finder)
->setFinder(
(new PhpCsFixer\Finder())
->in([__DIR__.'/src', __DIR__.'/tests'])
->append([__FILE__])
)
->setCacheFile('.php-cs-fixer.cache')
;
14 changes: 8 additions & 6 deletions src/Asset/EntrypointLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -33,7 +35,7 @@ class EntrypointLookup implements EntrypointLookupInterface, IntegrityDataProvid

private $strictMode;

public function __construct(string $entrypointJsonPath, CacheItemPoolInterface $cache = null, string $cacheKey = null, bool $strictMode = true)
public function __construct(string $entrypointJsonPath, ?CacheItemPoolInterface $cache = null, ?string $cacheKey = null, bool $strictMode = true)
{
$this->entrypointJsonPath = $entrypointJsonPath;
$this->cache = $cache;
Expand Down Expand Up @@ -96,10 +98,10 @@ private function validateEntryName(string $entryName): void
$withoutExtension = substr($entryName, 0, strrpos($entryName, '.'));

if (isset($entriesData['entrypoints'][$withoutExtension])) {
throw new EntrypointNotFoundException(sprintf('Could not find the entry "%s". Try "%s" instead (without the extension).', $entryName, $withoutExtension));
throw new EntrypointNotFoundException(\sprintf('Could not find the entry "%s". Try "%s" instead (without the extension).', $entryName, $withoutExtension));
}

throw new EntrypointNotFoundException(sprintf('Could not find the entry "%s" in "%s". Found: %s.', $entryName, $this->entrypointJsonPath, implode(', ', array_keys($entriesData['entrypoints']))));
throw new EntrypointNotFoundException(\sprintf('Could not find the entry "%s" in "%s". Found: %s.', $entryName, $this->entrypointJsonPath, implode(', ', array_keys($entriesData['entrypoints']))));
}
}

Expand All @@ -121,17 +123,17 @@ private function getEntriesData(): array
if (!$this->strictMode) {
return [];
}
throw new \InvalidArgumentException(sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist.', $this->entrypointJsonPath));
throw new \InvalidArgumentException(\sprintf('Could not find the entrypoints file from Webpack: the file "%s" does not exist.', $this->entrypointJsonPath));
}

$this->entriesData = json_decode(file_get_contents($this->entrypointJsonPath), true);

if (null === $this->entriesData) {
throw new \InvalidArgumentException(sprintf('There was a problem JSON decoding the "%s" file', $this->entrypointJsonPath));
throw new \InvalidArgumentException(\sprintf('There was a problem JSON decoding the "%s" file', $this->entrypointJsonPath));
}

if (!isset($this->entriesData['entrypoints'])) {
throw new \InvalidArgumentException(sprintf('Could not find an "entrypoints" key in the "%s" file', $this->entrypointJsonPath));
throw new \InvalidArgumentException(\sprintf('Could not find an "entrypoints" key in the "%s" file', $this->entrypointJsonPath));
}

if (isset($cached)) {
Expand Down
8 changes: 5 additions & 3 deletions src/Asset/EntrypointLookupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand All @@ -25,13 +27,13 @@ class EntrypointLookupCollection implements EntrypointLookupCollectionInterface

private $defaultBuildName;

public function __construct(ContainerInterface $buildEntrypoints, string $defaultBuildName = null)
public function __construct(ContainerInterface $buildEntrypoints, ?string $defaultBuildName = null)
{
$this->buildEntrypoints = $buildEntrypoints;
$this->defaultBuildName = $defaultBuildName;
}

public function getEntrypointLookup(string $buildName = null): EntrypointLookupInterface
public function getEntrypointLookup(?string $buildName = null): EntrypointLookupInterface
{
if (null === $buildName) {
if (null === $this->defaultBuildName) {
Expand All @@ -42,7 +44,7 @@ public function getEntrypointLookup(string $buildName = null): EntrypointLookupI
}

if (!$this->buildEntrypoints->has($buildName)) {
throw new UndefinedBuildException(sprintf('The build "%s" is not configured', $buildName));
throw new UndefinedBuildException(\sprintf('The build "%s" is not configured', $buildName));
}

return $this->buildEntrypoints->get($buildName);
Expand Down
4 changes: 3 additions & 1 deletion src/Asset/EntrypointLookupCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand All @@ -18,5 +20,5 @@ interface EntrypointLookupCollectionInterface
*
* @throws UndefinedBuildException if the build does not exist
*/
public function getEntrypointLookup(string $buildName = null): EntrypointLookupInterface;
public function getEntrypointLookup(?string $buildName = null): EntrypointLookupInterface;
}
2 changes: 2 additions & 0 deletions src/Asset/EntrypointLookupInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Asset/IntegrityDataProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
16 changes: 9 additions & 7 deletions src/Asset/TagRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -34,7 +36,7 @@ public function __construct(
array $defaultAttributes = [],
array $defaultScriptAttributes = [],
array $defaultLinkAttributes = [],
EventDispatcherInterface $eventDispatcher = null
?EventDispatcherInterface $eventDispatcher = null,
) {
$this->entrypointLookupCollection = $entrypointLookupCollection;
$this->packages = $packages;
Expand All @@ -46,7 +48,7 @@ public function __construct(
$this->reset();
}

public function renderWebpackScriptTags(string $entryName, string $packageName = null, string $entrypointName = null, array $extraAttributes = []): string
public function renderWebpackScriptTags(string $entryName, ?string $packageName = null, ?string $entrypointName = null, array $extraAttributes = []): string
{
$entrypointName = $entrypointName ?: '_default';
$scriptTags = [];
Expand All @@ -72,7 +74,7 @@ public function renderWebpackScriptTags(string $entryName, string $packageName =
}
$attributes = $event->getAttributes();

$scriptTags[] = sprintf(
$scriptTags[] = \sprintf(
'<script %s></script>',
$this->convertArrayToAttributes($attributes)
);
Expand All @@ -83,7 +85,7 @@ public function renderWebpackScriptTags(string $entryName, string $packageName =
return implode('', $scriptTags);
}

public function renderWebpackLinkTags(string $entryName, string $packageName = null, string $entrypointName = null, array $extraAttributes = []): string
public function renderWebpackLinkTags(string $entryName, ?string $packageName = null, ?string $entrypointName = null, array $extraAttributes = []): string
{
$entrypointName = $entrypointName ?: '_default';
$scriptTags = [];
Expand All @@ -110,7 +112,7 @@ public function renderWebpackLinkTags(string $entryName, string $packageName = n
}
$attributes = $event->getAttributes();

$scriptTags[] = sprintf(
$scriptTags[] = \sprintf(
'<link %s>',
$this->convertArrayToAttributes($attributes)
);
Expand Down Expand Up @@ -144,7 +146,7 @@ public function reset(): void
];
}

private function getAssetPath(string $assetPath, string $packageName = null): string
private function getAssetPath(string $assetPath, ?string $packageName = null): string
{
if (null === $this->packages) {
throw new \Exception('To render the script or link tags, run "composer require symfony/asset".');
Expand Down Expand Up @@ -175,7 +177,7 @@ static function ($key, $value) {
return $key;
}

return sprintf('%s="%s"', $key, htmlentities($value));
return \sprintf('%s="%s"', $key, htmlentities($value));
},
array_keys($attributesMap),
$attributesMap
Expand Down
4 changes: 3 additions & 1 deletion src/CacheWarmer/EntrypointCacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand All @@ -24,7 +26,7 @@ public function __construct(array $cacheKeys, string $phpArrayFile)
parent::__construct($phpArrayFile);
}

protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, string $buildDir = null): bool
protected function doWarmUp(string $cacheDir, ArrayAdapter $arrayAdapter, ?string $buildDir = null): bool
{
foreach ($this->cacheKeys as $cacheKey => $path) {
// If the file does not exist then just skip past this entry point.
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/DependencyInjection/WebpackEncoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down Expand Up @@ -103,6 +105,6 @@ private function entrypointFactory(ContainerBuilder $container, string $name, st

private function getEntrypointServiceId(string $name): string
{
return sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
return \sprintf('webpack_encore.entrypoint_lookup[%s]', $name);
}
}
2 changes: 2 additions & 0 deletions src/Event/RenderAssetTagEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/PreLoadAssetsEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/EventListener/ResetAssetsEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/EntrypointNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Exception/UndefinedBuildException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

/*
* This file is part of the Symfony WebpackEncoreBundle package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
Expand Down
Loading