Skip to content

Commit

Permalink
Merge pull request #702 from stof/fix_ci
Browse files Browse the repository at this point in the history
Fix coding standards
  • Loading branch information
stof committed Jan 13, 2024
2 parents d93eac2 + 0fea2a9 commit 9ce92eb
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Expand Up @@ -82,3 +82,24 @@ jobs:

- name: Run phpstan
run: vendor-bin/phpstan/vendor/bin/phpstan analyse --ansi --no-progress

coding_styles:
name: Coding styles
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
coverage: "none"
php-version: "8.2"
ini-file: development

- name: Install dependencies
run: composer update --ansi --no-progress

- name: Run phpcs
run: vendor/bin/phpcs --extensions=php bin src tests *.php
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -11,7 +11,7 @@ rebuild-outputs: vendor
BUILD=1 vendor/bin/phpunit tests/InputTest.php

standard: vendor
vendor/bin/phpcs -s --standard=PSR12 --exclude=PSR12.Properties.ConstantVisibility --extensions=php bin src tests *.php
vendor/bin/phpcs -s --extensions=php bin src tests *.php

vendor: composer.json
composer update
Expand Down
12 changes: 8 additions & 4 deletions phpcs.xml.dist
@@ -1,12 +1,16 @@
<?xml version="1.0"?>
<ruleset name="PSR12 (adapted for PHP 5.6+)">
<ruleset name="PSR12 (adapted for PHP 5.6+)" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<rule ref="PSR12">
<!-- Ignore this PHP 7.1+ sniff as long as we support PHP 5.6+ -->
<exclude name="PSR12.Properties.ConstantVisibility.NotFound"/>

<!-- This sniff doesn't ignore comment blocks -->
<!--
<!-- PSR12 does not actually have a hard line length -->
<exclude name="Generic.Files.LineLength"/>
-->
</rule>
<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>*/tests/ApiTest\.php</exclude-pattern>
</rule>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>*/src/Exception/ServerException\.php</exclude-pattern>
</rule>
</ruleset>
27 changes: 13 additions & 14 deletions src/Compiler.php
Expand Up @@ -5841,13 +5841,13 @@ public function findImport($url, $currentDir = null)

if (! \is_null($file)) {
if (\is_array($dir)) {
$callableDescription = (\is_object($dir[0]) ? \get_class($dir[0]) : $dir[0]).'::'.$dir[1];
$callableDescription = (\is_object($dir[0]) ? \get_class($dir[0]) : $dir[0]) . '::' . $dir[1];
} elseif ($dir instanceof \Closure) {
$r = new \ReflectionFunction($dir);
if (false !== strpos($r->name, '{closure}')) {
$callableDescription = sprintf('closure{%s:%s}', $r->getFileName(), $r->getStartLine());
} elseif ($class = $r->getClosureScopeClass()) {
$callableDescription = $class->name.'::'.$r->name;
$callableDescription = $class->name . '::' . $r->name;
} else {
$callableDescription = $r->name;
}
Expand Down Expand Up @@ -5960,15 +5960,15 @@ private function checkImportPathConflicts(array $paths)
private function tryImportPathWithExtensions($path)
{
$result = array_merge(
$this->tryImportPath($path.'.sass'),
$this->tryImportPath($path.'.scss')
$this->tryImportPath($path . '.sass'),
$this->tryImportPath($path . '.scss')
);

if ($result) {
return $result;
}

return $this->tryImportPath($path.'.css');
return $this->tryImportPath($path . '.css');
}

/**
Expand All @@ -5978,7 +5978,7 @@ private function tryImportPathWithExtensions($path)
*/
private function tryImportPath($path)
{
$partial = dirname($path).'/_'.basename($path);
$partial = dirname($path) . '/_' . basename($path);

$candidates = [];

Expand All @@ -6004,7 +6004,7 @@ private function tryImportPathAsDirectory($path)
return null;
}

return $this->checkImportPathConflicts($this->tryImportPathWithExtensions($path.'/index'));
return $this->checkImportPathConflicts($this->tryImportPathWithExtensions($path . '/index'));
}

/**
Expand All @@ -6019,7 +6019,7 @@ private function getPrettyPath($path)
}

$normalizedPath = $path;
$normalizedRootDirectory = $this->rootDirectory.'/';
$normalizedRootDirectory = $this->rootDirectory . '/';

if (\DIRECTORY_SEPARATOR === '\\') {
$normalizedRootDirectory = str_replace('\\', '/', $normalizedRootDirectory);
Expand Down Expand Up @@ -7712,9 +7712,9 @@ private function HWBtoRGB($hue, $whiteness, $blackness)
$b = min(1.0 - $w, $b);

$rgb = $this->toRGB($hue, 100, 50);
for($i = 1; $i < 4; $i++) {
$rgb[$i] *= (1.0 - $w - $b);
$rgb[$i] = round($rgb[$i] + 255 * $w + 0.0001);
for ($i = 1; $i < 4; $i++) {
$rgb[$i] *= (1.0 - $w - $b);
$rgb[$i] = round($rgb[$i] + 255 * $w + 0.0001);
}

return $rgb;
Expand All @@ -7741,7 +7741,6 @@ private function RGBtoHWB($red, $green, $blue)
if ((int) $d === 0) {
$h = 0;
} else {

if ($red == $max) {
$h = 60 * ($green - $blue) / $d;
} elseif ($green == $max) {
Expand All @@ -7751,7 +7750,7 @@ private function RGBtoHWB($red, $green, $blue)
}
}

return [Type::T_HWB, fmod($h, 360), $min / 255 * 100, 100 - $max / 255 *100];
return [Type::T_HWB, fmod($h, 360), $min / 255 * 100, 100 - $max / 255 * 100];
}


Expand Down Expand Up @@ -8108,7 +8107,7 @@ protected function libAdjustColor($args)
protected static $libChangeColor = ['color', 'kwargs...'];
protected function libChangeColor($args)
{
return $this->alterColor($args,'change', function ($base, $alter, $max) {
return $this->alterColor($args, 'change', function ($base, $alter, $max) {
if ($alter === null) {
return $base;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Node/Number.php
Expand Up @@ -564,7 +564,7 @@ public function equals(Number $other)

try {
return $this->coerceUnits($other, function ($num1, $num2) {
return round($num1,self::PRECISION) == round($num2, self::PRECISION);
return round($num1, self::PRECISION) == round($num2, self::PRECISION);
});
} catch (SassScriptException $e) {
return false;
Expand Down
2 changes: 1 addition & 1 deletion tests/SassSpecTest.php
Expand Up @@ -294,7 +294,7 @@ public function testTests($name, $input, $output)
mkdir($basedir, 0777, true);
}

$inputPath = $basedir.'/input.scss';
$inputPath = $basedir . '/input.scss';
file_put_contents($inputPath, $scss);

// SassSpec use @import "core_functions/.../..."
Expand Down

0 comments on commit 9ce92eb

Please sign in to comment.