Skip to content

Commit

Permalink
allow php8 (#3)
Browse files Browse the repository at this point in the history
Allow php8+ and drop lower than php7.4
  • Loading branch information
plandolt authored Aug 9, 2022
1 parent d99bce8 commit f8c0342
Show file tree
Hide file tree
Showing 28 changed files with 234 additions and 186 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: build
on: [push]
jobs:
build:
name: PHP on ${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.composer-flags }}
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.4', '8.0', '8.1']
stability: [prefer-lowest, prefer-stable]
include:
- php: '8.2'
flags: "--ignore-platform-req=php"
stability: prefer-stable
steps:
- name: Checkout code
uses: actions/checkout@v3


- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: xdebug
tools: composer:v2

- name: Check PHP Version
run: php -v

- name: Validate composer files
run: composer validate --strict

- name: Install dependencies
run: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress ${{ matrix.flags }}

- name: Run Unit tests with coverage
run: composer phpunit -- ${{ matrix.phpunit-flags }}

- name: Run static analysis
run: composer phpstan
if: ${{ matrix.php == '8.1' && matrix.stability == 'prefer-stable'}}

- name: Run Coding style rules
run: composer phpcs:fix
if: ${{ matrix.php == '8.1' && matrix.stability == 'prefer-stable'}}
32 changes: 32 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This document has been generated with
* https://mlocati.github.io/php-cs-fixer-configurator/#version:2.16.4|configurator
* you can change this configuration by importing this file.
*/
$config = new PhpCsFixer\Config();
return $config
->setRiskyAllowed(true)
->setRules([
'@PSR12' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'backtick_to_shell_exec' => true,
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true
],
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'mb_str_functions' => true,
'no_php4_constructor' => true,
'phpdoc_line_span' => ['const' => 'single'],
'self_static_accessor' => true,
'static_lambda' => true,
'no_unused_imports' => true,
])
->setFinder(PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
);
17 changes: 0 additions & 17 deletions .php_cs.dist

This file was deleted.

11 changes: 0 additions & 11 deletions .scrutinizer.yml

This file was deleted.

34 changes: 0 additions & 34 deletions .travis.yml

This file was deleted.

10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ artack/color
> color conversions and transitions (e.g. interpolation).

[![Build Status](https://img.shields.io/travis/ARTACK/color.svg?style=flat)](https://travis-ci.org/ARTACK/color)
[![Scrutinizer Quality Score](https://img.shields.io/scrutinizer/g/artack/color.svg?style=flat)](https://scrutinizer-ci.com/g/artack/color/)
[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/artack/color.svg)](https://scrutinizer-ci.com/g/artack/color/)

[![Latest Release](https://img.shields.io/packagist/v/artack/color.svg)](https://packagist.org/packages/artack/color)
[![MIT License](https://img.shields.io/packagist/l/artack/color.svg)](http://opensource.org/licenses/MIT)
[![Total Downloads](https://img.shields.io/packagist/dt/artack/color.svg)](https://packagist.org/packages/artack/color)
Expand All @@ -22,13 +18,13 @@ Features
- Provides conversion between all class representation
- Provides transitions between colors (e.g. interpolation)
- Provides clear exceptions to be able to handle library exceptions
- Compatible with PHP >= 7.
- Compatible with PHP >= 7 and >= 8.


Installation
------------

You can install ARTACK's color library through [Composer](https://getcomposer.org):
You can install this color library through [Composer](https://getcomposer.org):

```shell
$ composer require artack/color
Expand Down Expand Up @@ -60,6 +56,6 @@ $RGBGreen = new RGB(0, 255, 0); // green

$RGBInterpolated = $transition->interpolate(RGB::class, $RGBRed, $RGBGreen, 100, 200); // should be ~yellow

// Interpolation will give better results when using HSV Transition. Colors get converted automaticly if needed.
// Interpolation will give better results when using HSV Transition. Colors get converted automatically if needed.
$HSVInterpolated = $transition->interpolate(HSV::class, $RGBRed, $RGBGreen, 100, 200); // should be ~yellow
```
34 changes: 29 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,43 @@
}
],
"require": {
"php": "^7.0",
"php": "^7.4|^8.0",
"webmozart/assert": "^1.2",
"clue/graph": "^0.9.0",
"graphp/algorithms": "^0.8.1"
},
"autoload": {
"psr-4": {"Artack\\Color\\": "src/"}
"psr-4": {
"Artack\\Color\\": "src/"
}
},
"autoload-dev": {
"psr-4": { "Artack\\Color\\": "tests/" }
"psr-4": {
"Artack\\Color\\": "tests/"
}
},
"require-dev": {
"phpunit/phpunit": "^6.5",
"symfony/var-dumper": "^3.4"
"friendsofphp/php-cs-fixer": "^v3.9",
"phpstan/phpstan": "^1.8",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-webmozart-assert": "^1.2",
"phpunit/phpunit": "^9.5"
},
"scripts": {
"phpcs": "php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
"phpstan": "phpstan analyse -c phpstan.neon --ansi",
"phpunit": "XDEBUG_MODE=coverage phpunit --coverage-text",
"test": [
"@phpunit",
"@phpstan",
"@phpcs"
]
},
"scripts-descriptions": {
"phpcs": "Runs coding style test suite",
"phpstan": "Runs complete codebase static analysis",
"phpunit": "Runs unit and functional testing",
"test": "Runs full test suite"
}
}
11 changes: 11 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
level: max
paths:
- src
# checkGenericClassInNonGenericObjectType: false
# checkMissingIterableValueType: false
28 changes: 11 additions & 17 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="arack/color test suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<!--<listeners>-->
<!--<listener class="\Mockery\Adapter\Phpunit\TestListener" />-->
<!--</listeners>-->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="arack/color test suite">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
8 changes: 4 additions & 4 deletions src/Color/CMYK.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

class CMYK extends Color
{
private $cyan;
private $magenta;
private $yellow;
private $key;
private float $cyan;
private float $magenta;
private float $yellow;
private float $key;

public function __construct(float $cyan, float $magenta, float $yellow, float $key)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Color/HEX.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class HEX extends Color
{
private $red;
private $green;
private $blue;
private string $red;
private string $green;
private string $blue;

public function __construct(string $red, string $green, string $blue)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Color/HSL.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class HSL extends Color
{
private $hue;
private $saturation;
private $lightness;
private int $hue;
private float $saturation;
private float $lightness;

public function __construct(int $hue, float $saturation, float $lightness)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Color/HSV.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class HSV extends Color
{
private $hue;
private $saturation;
private $value;
private int $hue;
private float $saturation;
private float $value;

public function __construct(int $hue, float $saturation, float $value)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Color/RGB.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

class RGB extends Color
{
private $red;
private $green;
private $blue;
private int $red;
private int $green;
private int $blue;

public function __construct(int $red, int $green, int $blue)
{
Expand Down
8 changes: 5 additions & 3 deletions src/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

use Artack\Color\Color\Color;

use function get_class;

class Converter
{
private $converterGraph;
private ConverterGraph $converterGraph;

public function __construct(ConverterGraph $converterGraph)
{
Expand All @@ -17,11 +19,11 @@ public function __construct(ConverterGraph $converterGraph)

public function convert(Color $color, string $fqcn): Color
{
if (\get_class($color) === $fqcn) {
if (get_class($color) === $fqcn) {
return clone $color;
}

foreach ($this->converterGraph->getConverterChain(\get_class($color), $fqcn) as $converter) {
foreach ($this->converterGraph->getConverterChain(get_class($color), $fqcn) as $converter) {
$color = $converter->convert($color);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Converter/HEXToRGBConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public function convert(Color $color): Color
/* @var HEX $color */
Assert::isInstanceOf($color, HEX::class, sprintf('color should be an instance of [%s]', HEX::class));

$red = hexdec($color->getRed());
$green = hexdec($color->getGreen());
$blue = hexdec($color->getBlue());
$red = (int) hexdec($color->getRed());
$green = (int) hexdec($color->getGreen());
$blue = (int) hexdec($color->getBlue());

return new RGB($red, $green, $blue);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Converter/HSLToRGBConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Artack\Color\Color\Color;
use Artack\Color\Color\HSL;
use Artack\Color\Color\RGB;
use RuntimeException;
use Webmozart\Assert\Assert;

class HSLToRGBConverter implements ConverterInterface
Expand Down Expand Up @@ -55,6 +56,8 @@ public function convert(Color $color): Color
$green = 0;
$blue = $x;
break;
default:
throw new RuntimeException();
}

return new RGB((int) round(($red + $m) * 255), (int) round(($green + $m) * 255), (int) round(($blue + $m) * 255));
Expand Down
Loading

0 comments on commit f8c0342

Please sign in to comment.