Skip to content

Commit

Permalink
Update coding style to PSR-12
Browse files Browse the repository at this point in the history
  • Loading branch information
bennothommo committed Jul 3, 2024
1 parent a6027f1 commit 738d59c
Show file tree
Hide file tree
Showing 151 changed files with 654 additions and 348 deletions.
14 changes: 10 additions & 4 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
<?xml version="1.0"?>
<ruleset name="October CMS">
<description>The coding standard for October CMS.</description>
<rule ref="PSR2">
<ruleset name="Winter CMS">
<description>The coding standard for Winter CMS.</description>
<rule ref="PSR12">
<!--
Exceptions to the PSR-2 guidelines as per our Developer Guide:
https://octobercms.com/help/guidelines/developer#psr-exceptions
https://wintercms.com/docs/v1.2/docs/architecture/developer-guide#exceptions-to-the-standard
-->
<exclude name="PSR1.Methods.CamelCapsMethodName.NotCamelCaps" />
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseBrace" />
<exclude name="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace" />

<!-- We're not enforcing a line length limit -->
<exclude name="Generic.Files.LineLength" />
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
Expand All @@ -19,6 +22,9 @@
<exclude-pattern>*/tests/*</exclude-pattern>
</rule>

<arg name="extensions" value="php" />
<arg name="colors" />

<file>src/</file>
<file>tests/</file>

Expand Down
6 changes: 4 additions & 2 deletions src/Assetic/Asset/AssetCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\Contracts\Cache\CacheInterface;
use Assetic\Contracts\Filter\FilterInterface;
Expand Down Expand Up @@ -159,6 +161,6 @@ private static function getCacheKey(AssetInterface $asset, FilterInterface $addi
$cacheKey .= serialize($values);
}

return md5($cacheKey.$salt);
return md5($cacheKey . $salt);
}
}
4 changes: 3 additions & 1 deletion src/Assetic/Asset/AssetCollection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Traversable;
use Assetic\Asset\Iterator\AssetCollectionFilterIterator;
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Asset/AssetReference.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\AssetManager;
use Assetic\Contracts\Filter\FilterInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Asset/BaseAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\Filter\FilterCollection;
use Assetic\Contracts\Filter\FilterInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Asset/FileAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\Contracts\Filter\FilterInterface;
use Assetic\Util\VarUtils;
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Asset/GlobAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Traversable;
use Assetic\Contracts\Filter\FilterInterface;
Expand Down
8 changes: 5 additions & 3 deletions src/Assetic/Asset/HttpAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\Contracts\Filter\FilterInterface;
use Assetic\Util\VarUtils;
Expand Down Expand Up @@ -26,7 +28,7 @@ class HttpAsset extends BaseAsset
public function __construct($sourceUrl, $filters = [], $ignoreErrors = false, array $vars = [])
{
if (0 === strpos($sourceUrl ?: '', '//')) {
$sourceUrl = 'http:'.$sourceUrl;
$sourceUrl = 'http:' . $sourceUrl;
} elseif (false === strpos($sourceUrl ?: '', '://')) {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid URL.', $sourceUrl));
}
Expand All @@ -37,7 +39,7 @@ public function __construct($sourceUrl, $filters = [], $ignoreErrors = false, ar
list($scheme, $url) = explode('://', $sourceUrl, 2);
list($host, $path) = explode('/', $url, 2);

parent::__construct($filters, $scheme.'://'.$host, $path, $vars);
parent::__construct($filters, $scheme . '://' . $host, $path, $vars);
}

public function load(FilterInterface $additionalFilter = null)
Expand Down
6 changes: 4 additions & 2 deletions src/Assetic/Asset/Iterator/AssetCollectionFilterIterator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset\Iterator;
<?php

namespace Assetic\Asset\Iterator;

use RecursiveFilterIterator;

Expand Down Expand Up @@ -54,7 +56,7 @@ public function accept(): bool
$sourceRoot = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
if ($sourceRoot && $sourcePath) {
$source = $sourceRoot.'/'.$sourcePath;
$source = $sourceRoot . '/' . $sourcePath;
if (in_array($source, $this->sources)) {
$duplicate = true;
} else {
Expand Down
8 changes: 5 additions & 3 deletions src/Assetic/Asset/Iterator/AssetCollectionIterator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset\Iterator;
<?php

namespace Assetic\Asset\Iterator;

use RecursiveIterator;
use Assetic\Contracts\Asset\AssetCollectionInterface;
Expand Down Expand Up @@ -30,7 +32,7 @@ public function __construct(AssetCollectionInterface $coll, \SplObjectStorage $c
if (false === $pos = strrpos($this->output ?: '', '.')) {
$this->output .= '_*';
} else {
$this->output = substr($this->output, 0, $pos).'_*'.substr($this->output, $pos);
$this->output = substr($this->output, 0, $pos) . '_*' . substr($this->output, $pos);
}
}

Expand Down Expand Up @@ -111,7 +113,7 @@ public function getChildren(): ?RecursiveIterator
private function removeDuplicateVar($name)
{
foreach ($this->vars as $var) {
$var = '{'.$var.'}';
$var = '{' . $var . '}';
if (false !== strpos($name ?: '', $var) && false !== strpos($this->output ?: '', $var)) {
$name = str_replace($var, '', $name);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Asset/MockAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\Asset\AssetInterface;
use Assetic\Filter\FilterInterface;
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Asset/StringAsset.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Asset;
<?php

namespace Assetic\Asset;

use Assetic\Contracts\Filter\FilterInterface;

Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/AssetManager.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic;
<?php

namespace Assetic;

use Assetic\Contracts\Asset\AssetInterface;

Expand Down
10 changes: 6 additions & 4 deletions src/Assetic/AssetWriter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic;
<?php

namespace Assetic;

use Assetic\Contracts\Asset\AssetInterface;
use Assetic\Util\VarUtils;
Expand Down Expand Up @@ -49,7 +51,7 @@ public function writeAsset(AssetInterface $asset)
$asset->setValues($combination);

static::write(
$this->dir.'/'.VarUtils::resolve(
$this->dir . '/' . VarUtils::resolve(
$asset->getTargetPath(),
$asset->getVars(),
$asset->getValues()
Expand All @@ -62,11 +64,11 @@ public function writeAsset(AssetInterface $asset)
protected static function write($path, $contents)
{
if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory '.$dir);
throw new \RuntimeException('Unable to create directory ' . $dir);
}

if (false === @file_put_contents($path, $contents)) {
throw new \RuntimeException('Unable to write file '.$path);
throw new \RuntimeException('Unable to write file ' . $path);
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Assetic/Cache/ArrayCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Cache;
<?php

namespace Assetic\Cache;

use Assetic\Contracts\Cache\CacheInterface;

Expand All @@ -25,7 +27,7 @@ public function has($key)
public function get($key)
{
if (!$this->has($key)) {
throw new \RuntimeException('There is no cached value for '.$key);
throw new \RuntimeException('There is no cached value for ' . $key);
}

return $this->cache[$key];
Expand Down
16 changes: 9 additions & 7 deletions src/Assetic/Cache/ConfigCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Cache;
<?php

namespace Assetic\Cache;

/**
* A config cache stores values using var_export() and include.
Expand Down Expand Up @@ -43,13 +45,13 @@ public function set($resource, $value)

if (!is_dir($dir = dirname($path)) && false === @mkdir($dir, 0777, true)) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Unable to create directory '.$dir);
throw new \RuntimeException('Unable to create directory ' . $dir);
// @codeCoverageIgnoreEnd
}

if (false === @file_put_contents($path, sprintf("<?php\n\n// $resource\nreturn %s;\n", var_export($value, true)))) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Unable to write file '.$path);
throw new \RuntimeException('Unable to write file ' . $path);
// @codeCoverageIgnoreEnd
}
}
Expand All @@ -66,7 +68,7 @@ public function get($resource)
$path = $this->getSourcePath($resource);

if (!file_exists($path)) {
throw new \RuntimeException('There is no cached value for '.$resource);
throw new \RuntimeException('There is no cached value for ' . $resource);
}

return include $path;
Expand All @@ -84,12 +86,12 @@ public function getTimestamp($resource)
$path = $this->getSourcePath($resource);

if (!file_exists($path)) {
throw new \RuntimeException('There is no cached value for '.$resource);
throw new \RuntimeException('There is no cached value for ' . $resource);
}

if (false === $mtime = @filemtime($path)) {
// @codeCoverageIgnoreStart
throw new \RuntimeException('Unable to determine file mtime for '.$path);
throw new \RuntimeException('Unable to determine file mtime for ' . $path);
// @codeCoverageIgnoreEnd
}

Expand All @@ -107,6 +109,6 @@ private function getSourcePath($resource)
{
$key = md5($resource);

return $this->dir.'/'.$key[0].'/'.$key.'.php';
return $this->dir . '/' . $key[0] . '/' . $key . '.php';
}
}
12 changes: 7 additions & 5 deletions src/Assetic/Cache/ExpiringCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Cache;
<?php

namespace Assetic\Cache;

use Assetic\Contracts\Cache\CacheInterface;

Expand All @@ -21,11 +23,11 @@ public function __construct(CacheInterface $cache, $lifetime)
public function has($key)
{
if ($this->cache->has($key)) {
if (time() < $this->cache->get($key.'.expires')) {
if (time() < $this->cache->get($key . '.expires')) {
return true;
}

$this->cache->remove($key.'.expires');
$this->cache->remove($key . '.expires');
$this->cache->remove($key);
}

Expand All @@ -39,13 +41,13 @@ public function get($key)

public function set($key, $value)
{
$this->cache->set($key.'.expires', time() + $this->lifetime);
$this->cache->set($key . '.expires', time() + $this->lifetime);
$this->cache->set($key, $value);
}

public function remove($key)
{
$this->cache->remove($key.'.expires');
$this->cache->remove($key . '.expires');
$this->cache->remove($key);
}
}
20 changes: 11 additions & 9 deletions src/Assetic/Cache/FilesystemCache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Cache;
<?php

namespace Assetic\Cache;

use Assetic\Contracts\Cache\CacheInterface;

Expand All @@ -18,15 +20,15 @@ public function __construct($dir)

public function has($key)
{
return file_exists($this->dir.'/'.$key);
return file_exists($this->dir . '/' . $key);
}

public function get($key)
{
$path = $this->dir.'/'.$key;
$path = $this->dir . '/' . $key;

if (!file_exists($path)) {
throw new \RuntimeException('There is no cached value for '.$key);
throw new \RuntimeException('There is no cached value for ' . $key);
}

return file_get_contents($path);
Expand All @@ -35,22 +37,22 @@ public function get($key)
public function set($key, $value)
{
if (!is_dir($this->dir) && false === @mkdir($this->dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory '.$this->dir);
throw new \RuntimeException('Unable to create directory ' . $this->dir);
}

$path = $this->dir.'/'.$key;
$path = $this->dir . '/' . $key;

if (false === @file_put_contents($path, $value)) {
throw new \RuntimeException('Unable to write file '.$path);
throw new \RuntimeException('Unable to write file ' . $path);
}
}

public function remove($key)
{
$path = $this->dir.'/'.$key;
$path = $this->dir . '/' . $key;

if (file_exists($path) && false === @unlink($path)) {
throw new \RuntimeException('Unable to remove file '.$path);
throw new \RuntimeException('Unable to remove file ' . $path);
}
}
}
4 changes: 3 additions & 1 deletion src/Assetic/Contracts/Asset/AssetCollectionInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Contracts\Asset;
<?php

namespace Assetic\Contracts\Asset;

/**
* An asset collection.
Expand Down
4 changes: 3 additions & 1 deletion src/Assetic/Contracts/Asset/AssetInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Assetic\Contracts\Asset;
<?php

namespace Assetic\Contracts\Asset;

use Assetic\Contracts\Filter\FilterInterface;

Expand Down
Loading

0 comments on commit 738d59c

Please sign in to comment.