Skip to content

Commit

Permalink
feature: upgrade to php8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jeojhx committed Feb 22, 2022
1 parent 380c8dd commit ee5a892
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 59 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Code Quality

on:
push:
branches: [ master ]
pull_request: ~

jobs:
test-php-80:
name: Code quality PHP 8.0
runs-on: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: xdebug

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Lint
run: composer lint:check

- name: PHP Static Analysis
run: composer phpstan

- name: Unit Test
run: composer phpunit
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
/.idea
/bin
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
/composer.lock
/coverage.xml
63 changes: 63 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests');

$config = new PhpCsFixer\Config();
$config
->setRules([
'@Symfony' => true,
'@PHP71Migration:risky' => true,
'@PHPUnit60Migration:risky' => true,
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'concat_space' => ['spacing' => 'one'],
'class_attributes_separation' => ['elements' => ['method'=>'one']],
'declare_strict_types' => true,
'increment_style' => ['style' => 'post'],
'list_syntax' => ['syntax' => 'short'],
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
'method_chaining_indentation' => true,
'modernize_types_casting' => true,
'multiline_whitespace_before_semicolons' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => false,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_imports' => true,
'phpdoc_align' => false,
'phpdoc_order' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'return_assignment' => true,
'single_blank_line_at_eof' => true,
'single_line_comment_style' => true,
'ternary_to_null_coalescing' => true,
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
'void_return' => true,
])
->setFinder($finder)
->setUsingCache(true)
->setRiskyAllowed(true);
;

// special handling of fabbot.io service if it's using too old PHP CS Fixer version
if (false !== getenv('FABBOT_IO')) {
try {
PhpCsFixer\FixerFactory::create()
->registerBuiltInFixers()
->registerCustomFixers($config->getCustomFixers())
->useRuleSet(new PhpCsFixer\RuleSet($config->getRules()))
;
} catch (PhpCsFixer\ConfigurationException\InvalidConfigurationException $e) {
$config->setRules([]);
} catch (UnexpectedValueException $e) {
$config->setRules([]);
} catch (InvalidArgumentException $e) {
$config->setRules([]);
}
}

return $config;
34 changes: 0 additions & 34 deletions .php_cs

This file was deleted.

21 changes: 16 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
"homepage": "https://github.com/linioit/microlog",
"license": "BSD-3-Clause",
"require": {
"php": ">=7.1",
"psr/log": "^1.0",
"monolog/monolog": "^1.23"
"php": "^7.4 || ^8.0",
"psr/log": "^1.0.1 || ^2.0 || ^3.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0 || ^7.0",
"friendsofphp/php-cs-fixer": "^2.11"
"phpunit/phpunit": "^8.5",
"friendsofphp/php-cs-fixer": "^3.6",
"phpstan/phpstan": "^0.12"
},
"autoload": {
"psr-4": {
Expand All @@ -23,5 +23,16 @@
"psr-4": {
"Linio\\Component\\Microlog\\": "tests/"
}
},
"scripts": {
"lint": "php-cs-fixer fix --verbose --show-progress=dots",
"lint:check": "php-cs-fixer fix --dry-run --verbose --show-progress=dots",
"phpunit": "phpunit",
"phpstan": "phpstan analyze",
"test": [
"@lint:check",
"@phpunit",
"@phpstan"
]
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
checkMissingIterableValueType: false
paths:
- src
18 changes: 9 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
backupGlobals="false"
colors="true"
convertErrorsToExceptions="false"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
syntaxCheck="true"
stopOnFailure="false"
bootstrap="./vendor/autoload.php">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/8.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuites>
<testsuite name="Linio Framework Test Suite">
<directory>./tests</directory>
Expand Down
20 changes: 10 additions & 10 deletions src/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class Log
{
const DEFAULT_CHANNEL = 'default';
public const DEFAULT_CHANNEL = 'default';

/**
* @var LoggerInterface[]
Expand All @@ -25,7 +25,7 @@ public static function setLoggerForChannel(LoggerInterface $logger, string $chan
/**
* System is unusable.
*/
public static function emergency($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function emergency(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::EMERGENCY, $message, $context, $channel);
}
Expand All @@ -36,7 +36,7 @@ public static function emergency($message, array $context = [], string $channel
* Example: Entire website down, database unavailable, etc. This should
* trigger the SMS alerts and wake you up.
*/
public static function alert($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function alert(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::ALERT, $message, $context, $channel);
}
Expand All @@ -46,7 +46,7 @@ public static function alert($message, array $context = [], string $channel = se
*
* Example: Application component unavailable, unexpected exception.
*/
public static function critical($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function critical(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::CRITICAL, $message, $context, $channel);
}
Expand All @@ -55,7 +55,7 @@ public static function critical($message, array $context = [], string $channel =
* Runtime errors that do not require immediate action but should typically
* be logged and monitored.
*/
public static function error($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function error(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::ERROR, $message, $context, $channel);
}
Expand All @@ -66,15 +66,15 @@ public static function error($message, array $context = [], string $channel = se
* Example: Use of deprecated APIs, poor use of an API, undesirable things
* that are not necessarily wrong.
*/
public static function warning($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function warning(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::WARNING, $message, $context, $channel);
}

/**
* Normal but significant events.
*/
public static function notice($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function notice(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::NOTICE, $message, $context, $channel);
}
Expand All @@ -84,23 +84,23 @@ public static function notice($message, array $context = [], string $channel = s
*
* Example: User logs in, SQL logs.
*/
public static function info($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function info(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::INFO, $message, $context, $channel);
}

/**
* Detailed debug information.
*/
public static function debug($message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function debug(string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::log(LogLevel::DEBUG, $message, $context, $channel);
}

/**
* Logs with an arbitrary level.
*/
public static function log($level, $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
public static function log(string $level, string $message, array $context = [], string $channel = self::DEFAULT_CHANNEL): void
{
self::getLoggerForChannel($channel)->log($level, $message, $context);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ThrowableProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class ThrowableProcessor
{
public function __invoke(array $record)
public function __invoke(array $record): array
{
if (!$record['message'] instanceof Throwable) {
return $record;
Expand Down

0 comments on commit ee5a892

Please sign in to comment.