Skip to content

Commit

Permalink
syntax update, phpstan, code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Gappa committed Jun 7, 2022
1 parent 1eb7455 commit 20c8b1c
Show file tree
Hide file tree
Showing 32 changed files with 102 additions and 136 deletions.
2 changes: 1 addition & 1 deletion phpstan/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ parameters:
excludePaths:
- %currentWorkingDirectory%/tests/temp/*

level: 7
level: 8

checkMissingIterableValueType: false

Expand Down
7 changes: 4 additions & 3 deletions src/Compiler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader;

Expand All @@ -17,7 +17,6 @@
*/
class Compiler
{

private IFileCollection $collection;
private IOutputNamingConvention $namingConvention;
private string $outputDir;
Expand Down Expand Up @@ -206,7 +205,9 @@ protected function generateFiles(array $files, array $watchFiles = []): File
{
$name = $this->namingConvention->getFilename($files, $this);
$path = $this->outputDir . '/' . $name;
$lastModified = $this->checkLastModified ? $this->getLastModified($watchFiles) : 0;
$lastModified = $this->checkLastModified
? $this->getLastModified($watchFiles)
: 0;

if (!file_exists($path) || $lastModified > filemtime($path) || $this->debugging === true) {
// disabled: https://github.com/nette/safe-stream/pull/5
Expand Down
3 changes: 2 additions & 1 deletion src/Contract/IBatchCollection.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php
declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Contract;

interface IBatchCollection
{
public function getBatches(): array;

public function addBatch(string $type, string $name, array $batch): void;
}
2 changes: 1 addition & 1 deletion src/Contract/IFileCollection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Contract;

Expand Down
2 changes: 1 addition & 1 deletion src/Contract/IOutputNamingConvention.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Contract;

Expand Down
2 changes: 1 addition & 1 deletion src/Contract/IWebloaderAssetProvider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Contract;

Expand Down
7 changes: 3 additions & 4 deletions src/DefaultOutputNamingConvention.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader;

Expand All @@ -13,14 +13,13 @@
*/
class DefaultOutputNamingConvention implements IOutputNamingConvention
{

private string $prefix = '';
private string $suffix = '';


public static function createCssConvention(): self
{
$convention = new self();
$convention = new self;
$convention->setSuffix('.css');

return $convention;
Expand All @@ -29,7 +28,7 @@ public static function createCssConvention(): self

public static function createJsConvention(): self
{
$convention = new self();
$convention = new self;
$convention->setSuffix('.js');

return $convention;
Expand Down
3 changes: 1 addition & 2 deletions src/Exception/BatchAlreadyExistsException.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php
declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Exception;

use WebLoader\Exception\WebLoaderException;

class BatchAlreadyExistsException extends WebLoaderException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/CompilationException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Exception;

Expand Down
3 changes: 1 addition & 2 deletions src/Exception/FileNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Exception;

use WebLoader\Exception\WebLoaderException;

/**
* FileNotFoundException
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/WebLoaderException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Exception;

Expand Down
2 changes: 1 addition & 1 deletion src/File.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader;

Expand Down
7 changes: 2 additions & 5 deletions src/FileCollection.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader;

Expand All @@ -16,16 +16,13 @@
*/
class FileCollection implements IFileCollection
{

private string $root;
private array $files = [];
private array $watchFiles = [];
private array $remoteFiles = [];


public function __construct(?string $root = null)
public function __construct(private string $root)
{
$this->root = (string) $root;
}


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

class CssMinFilter
{

public function __invoke(string $code, Compiler $compiler, string $file = ''): string
{
$minifier = new Minifier;
Expand Down
16 changes: 6 additions & 10 deletions src/Filter/CssUrlsFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Filter;

Expand All @@ -16,20 +16,18 @@
*/
class CssUrlsFilter
{

protected string $basePath;
private string $docRoot;


public function __construct(string $docRoot, string $basePath = '/')
{
public function __construct(
string $docRoot,
protected string $basePath = '/'
) {
$this->docRoot = Path::normalize($docRoot);

if (!is_dir($this->docRoot)) {
throw new InvalidArgumentException('Given document root is not directory.');
}

$this->basePath = $basePath;
}


Expand Down Expand Up @@ -109,9 +107,7 @@ public function __invoke(string $code, Compiler $loader, ?string $file = null):

$self = $this;

$return = preg_replace_callback($regexp, function ($matches) use ($self, $file) {
return "url('" . $self->absolutizeUrl($matches[2], $matches[1], $file) . "')";
}, $code);
$return = preg_replace_callback($regexp, fn($matches) => "url('" . $self->absolutizeUrl($matches[2], $matches[1], $file) . "')", $code);

return (string) $return;
}
Expand Down
7 changes: 2 additions & 5 deletions src/Filter/LessBinFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Filter;

Expand All @@ -14,14 +14,11 @@
*/
class LessBinFilter
{

private string $bin;
private array $env;


public function __construct(string $bin = 'lessc', array $env = [])
public function __construct(private string $bin = 'lessc', array $env = [])
{
$this->bin = $bin;
$this->env = $env + $_ENV;
unset($this->env['argv'], $this->env['argc']);
}
Expand Down
5 changes: 2 additions & 3 deletions src/Filter/Process.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Filter;

Expand All @@ -19,8 +19,7 @@ public static function run(
?string $stdin = null,
?string $cwd = null,
?array $env = null
): string
{
): string {
$descriptorspec = [
0 => ['pipe', 'r'], // stdin
1 => ['pipe', 'w'], // stdout
Expand Down
11 changes: 3 additions & 8 deletions src/Filter/ScssFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Filter;

Expand All @@ -15,21 +15,16 @@
*/
class ScssFilter
{

private ?ScssCompiler $sc;


public function __construct(?ScssCompiler $sc = null)
public function __construct(private ?ScssCompiler $sc = null)
{
$this->sc = $sc;
}


private function getScssC(): ScssCompiler
{
// lazy loading
if (empty($this->sc)) {
$this->sc = new ScssCompiler();
$this->sc = new ScssCompiler;
}

return $this->sc;
Expand Down
7 changes: 2 additions & 5 deletions src/Filter/StylusFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Filter;

Expand All @@ -14,15 +14,12 @@
*/
class StylusFilter
{

public bool $compress = false;
public bool $includeCss = false;
private string $bin;


public function __construct(string $bin = 'stylus')
public function __construct(private string $bin = 'stylus')
{
$this->bin = $bin;
}


Expand Down
7 changes: 2 additions & 5 deletions src/Filter/TypeScriptFilter.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

declare(strict_types = 1);
declare(strict_types=1);

namespace WebLoader\Filter;

Expand All @@ -14,14 +14,11 @@
*/
class TypeScriptFilter
{

private ?string $bin;
private ?array $env;


public function __construct(string $bin = 'tsc', array $env = [])
public function __construct(private string $bin = 'tsc', array $env = [])
{
$this->bin = $bin;
$this->env = $env + $_ENV;
unset($this->env['argv'], $this->env['argc']);
}
Expand Down
Loading

0 comments on commit 20c8b1c

Please sign in to comment.