Skip to content

Commit

Permalink
php stan, rector, do not test eol php version (#2165)
Browse files Browse the repository at this point in the history
* php stan, rector, do not test eol php version

* rector

* tests

* Apply php-cs-fixer changes

Co-authored-by: nadar <nadar@users.noreply.github.com>
  • Loading branch information
nadar and nadar authored Nov 9, 2022
1 parent 9ec20bc commit b78e41d
Show file tree
Hide file tree
Showing 28 changed files with 119 additions and 42 deletions.
69 changes: 68 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,73 @@ env:
CC_TEST_REPORTER_ID: e104088a64c54b2a68debe43e4600b48f53a73441e99449223a9fa08c070cf97
jobs:

## PHPSTAN
phpstan:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@2.21.0
with:
php-version: '8.0'
extensions: mbstring, intl
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true

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

- name: PHPStan tests
run: composer phpstan

## Rector
rector:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@2.21.0
with:
php-version: '8.0'
extensions: mbstring, intl
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true

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

- name: Rector tests
run: composer rector

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply rector changes

# PHPCSFIXER
php-cs-fixer:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install
run: composer install

- name: Run php-cs-fixer
run: composer phpcsfixer

- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Apply php-cs-fixer changes

## PHP UNIT
phpunit:
name: PHP ${{ matrix.php }} on ${{ matrix.os }}
Expand All @@ -15,7 +82,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2']
php: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2']

services:
mysql:
Expand Down
2 changes: 1 addition & 1 deletion .php-cs-fixer.cache

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
In order to read more about upgrading and BC breaks have a look at the [UPGRADE Document](UPGRADE.md).

## 2.3.0

> Check the [UPGRADE document](UPGRADE.md) to read more about breaking changes.
+ [#2165](https://github.com/luyadev/luya/pull/2165) Official deprecated unit tests for php 7.0, 7.1

## 2.2.1 (5. October 2022)

+ [#2159](https://github.com/luyadev/luya/pull/2159) Added missing option to create menu items with a scheme instead of relative paths.
Expand Down
2 changes: 1 addition & 1 deletion core/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ private function appendConfig(&$config, ConfigDefinition $definition)

case ConfigDefinition::GROUP_CALLABLE:
call_user_func($definition->getConfig(), $this);
break;
break;
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/TagParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private function instantiatTag($tag)
{
if (!is_object($this->tags[$tag])) {
$this->tags[$tag] = Yii::createObject($this->tags[$tag]);
Yii::debug('tag parser object generated for:'. $tag, __CLASS__);
Yii::debug('tag parser object generated for:'. $tag, self::class);
}
}

Expand All @@ -153,8 +153,8 @@ private function parseTag($tag, $context)
// ensure tag is an object
$this->instantiatTag($tag);
// extract context
$value = isset($context['value']) ? $context['value'] : false;
$sub = isset($context['sub']) ? $context['sub'] : false;
$value = $context['value'] ?? false;
$sub = $context['sub'] ?? false;
// the sub value can contain escaped values, those values must be parsed back into the original state.
if ($sub) {
$sub = str_replace(['\)', '\('], [')', '('], $sub);
Expand Down
4 changes: 4 additions & 0 deletions core/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ LUYA UPGRADE

This document will help you upgrading from a LUYA Version into another. For more detailed informations about the breaking changes **click the issue detail link**, there you can examples of how to change your code.

## 2.3.0

+ [#2165](https://github.com/luyadev/luya/pull/2165) Official deprecated unit tests for php 7.0, 7.1, 7.2 and 7.3. The minium php version is now 7.4, see [php supported versions](https://www.php.net/supported-versions.php). The code keeps the same and should be backwards compatible but its not official tested anymore.

## 2.0.0

+ [#2068](https://github.com/luyadev/luya/issues/2068) In order to restore the auto register mechanism for csrf tokens either use `ActiveForms` or configure your component:
Expand Down
6 changes: 1 addition & 5 deletions core/base/Boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ public function run()

/**
* Run Cli-Application based on the provided config file.
*
* @return string|integer
*/
public function applicationConsole()
{
Expand Down Expand Up @@ -228,7 +226,7 @@ public function applicationConsole()
'enablePrettyUrl' => true,
'showScriptName' => false,
'baseUrl' => $baseUrl,
'hostInfo' => isset($config['consoleHostInfo']) ? $config['consoleHostInfo'] : null,
'hostInfo' => $config['consoleHostInfo'] ?? null,
],
],
]);
Expand All @@ -241,8 +239,6 @@ public function applicationConsole()

/**
* Run Web-Application based on the provided config file.
*
* @return string Returns the Yii Application run() method if mock is disabled. Otherwise returns void
*/
public function applicationWeb()
{
Expand Down
2 changes: 1 addition & 1 deletion core/base/HookEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ public function offsetUnset($offset)
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
return isset($this->_iterations[$offset]) ? $this->_iterations[$offset] : null;
return $this->_iterations[$offset] ?? null;
}
}
2 changes: 1 addition & 1 deletion core/base/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public static function registerTranslation($prefix, $basePath, array $fileMap)
*/
public static function staticBasePath()
{
$class = new \ReflectionClass(get_called_class());
$class = new \ReflectionClass(static::class);

return dirname($class->getFileName());
}
Expand Down
2 changes: 1 addition & 1 deletion core/console/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function selectModule(array $options = [])
$modules[$id] = $id;
}

$text = (isset($options['text'])) ? $options['text'] : 'Please select a module:';
$text = $options['text'] ?? 'Please select a module:';

return $this->select($text, $modules);
}
Expand Down
2 changes: 1 addition & 1 deletion core/console/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getModule()
*/
public function addLog($value)
{
$this->getImporter()->addLog(get_called_class(), $value);
$this->getImporter()->addLog(static::class, $value);
}

/**
Expand Down
1 change: 0 additions & 1 deletion core/console/commands/HealthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public function actionIndex()
/**
* Test Mail-Component (Use --verbose=1 to enable smtp debug output)
*
* @return boolean Whether successfull or not.
* @throws \Exception On smtp failure
*/
public function actionMailer()
Expand Down
6 changes: 3 additions & 3 deletions core/console/commands/views/module/readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* @var $ns The namespace where the module is stored in.
*/
?># <?= $humanName; ?> Module

<?= $luyaText; ?>

## Installation

In order to add the modules to your project go into the modules section of your config:
Expand All @@ -25,4 +25,4 @@
// ...
],
];
```
```
2 changes: 1 addition & 1 deletion core/texttospeech/TextToSpeechWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function run()
TextToSpeechAsset::register($this->view);

$config = Json::htmlEncode([
'text' => $this->text ? $this->text : '', // must be an empty string as it will checked with .length
'text' => $this->text ?: '', // must be an empty string as it will checked with .length
'language' => Yii::$app->language,
]);

Expand Down
1 change: 0 additions & 1 deletion core/theme/ThemeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ protected function getThemeDefinitions()
}

foreach (Yii::$app->getPackageInstaller()->getConfigs() as $config) {

/** @var PackageConfig $config */
foreach ($config->themes as $theme) {
if (strpos($theme, '@') === 0 || strpos($theme, '/') === 0) {
Expand Down
20 changes: 10 additions & 10 deletions core/traits/ErrorHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ public function getExceptionArray($exception)
} elseif (is_string($exception)) {
$_message = 'exception string: ' . $exception;
} elseif (is_array($exception)) {
$_message = isset($exception['message']) ? $exception['message'] : 'exception array dump: ' . print_r($exception, true);
$_file = isset($exception['file']) ? $exception['file'] : __FILE__;
$_line = isset($exception['line']) ? $exception['line'] : __LINE__;
$_message = $exception['message'] ?? 'exception array dump: ' . print_r($exception, true);
$_file = $exception['file'] ?? __FILE__;
$_line = $exception['line'] ?? __LINE__;
}

$exceptionName = 'Exception';
Expand All @@ -195,12 +195,12 @@ public function getExceptionArray($exception)
'message' => $_message,
'file' => $_file,
'line' => $_line,
'requestUri' => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null,
'serverName' => isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null,
'requestUri' => $_SERVER['REQUEST_URI'] ?? null,
'serverName' => $_SERVER['SERVER_NAME'] ?? null,
'date' => date('d.m.Y H:i'),
'trace' => $_trace,
'previousException' => $_previousException,
'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null,
'ip' => $_SERVER['REMOTE_ADDR'] ?? null,
'get' => isset($_GET) ? ArrayHelper::coverSensitiveValues($_GET, $this->sensitiveKeys) : [],
'post' => isset($_POST) ? ArrayHelper::coverSensitiveValues($_POST, $this->sensitiveKeys) : [],
'bodyParams' => Yii::$app instanceof Application ? ArrayHelper::coverSensitiveValues(Yii::$app->request->bodyParams) : [],
Expand Down Expand Up @@ -252,8 +252,8 @@ private function buildTrace($exception)
*/
private function buildTraceItem(array $item)
{
$file = isset($item['file']) ? $item['file'] : null;
$line = isset($item['line']) ? $item['line'] : null;
$file = $item['file'] ?? null;
$line = $item['line'] ?? null;
$contextLine = null;
$preContext = [];
$postContext = [];
Expand Down Expand Up @@ -296,8 +296,8 @@ private function buildTraceItem(array $item)
'context_line' => $contextLine,
'pre_context' => $preContext,
'post_context' => $postContext,
'function' => isset($item['function']) ? $item['function'] : null,
'class' => isset($item['class']) ? $item['class'] : null,
'function' => $item['function'] ?? null,
'class' => $item['class'] ?? null,
// currently arguments wont be transmited due to large amount of informations based on base object
//'args' => isset($item['args']) ? ArrayHelper::coverSensitiveValues($item['args'], $this->sensitiveKeys) : [],
], function ($value) {
Expand Down
1 change: 0 additions & 1 deletion core/traits/RestBehaviorsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public function behaviors()
unset($behaviors['authenticator']);

if ($this->getUserAuthClass()) {

// change to admin user auth class
$behaviors['authenticator'] = [
'class' => CompositeAuth::class,
Expand Down
2 changes: 1 addition & 1 deletion core/web/Composition.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function getKey($key, $defaultValue = false)
{
$this->getKeys();

return isset($this->_keys[$key]) ? $this->_keys[$key] : $defaultValue;
return $this->_keys[$key] ?? $defaultValue;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion core/web/CompositionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getResolvedKeyValue($key)
{
$keys = $this->resolvedValues;

return isset($keys[$key]) ? $keys[$key] : false;
return $keys[$key] ?? false;
}

/**
Expand Down
1 change: 0 additions & 1 deletion core/web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public function getViewPath()
} elseif (is_array($this->module->viewMap)) {
$currentAction = $this->id . '/' . ($this->action ? $this->action->id : $this->defaultAction);
foreach ($this->module->viewMap as $action => $viewPath) {

// Special case for map all views of controller
if ($action === '*') {
return $viewPath . '/' . $this->id;
Expand Down
1 change: 0 additions & 1 deletion core/web/Svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public function run()
{
// Cache generated code
return $this->getOrSetHasCache(['svg', $this->folder, $this->file, $this->cssClass, $this->symbolName], function () {

// Check if file ends with .svg, if not add the extension
$svgFile = StringHelper::endsWith($this->file, '.svg') ? $this->file : $this->file . '.svg';

Expand Down
2 changes: 1 addition & 1 deletion core/web/jsonld/AggregateRating.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setItemReviewed(ThingInterface $thing)
*/
public function getItemReviewed()
{
$this->_itemReviewed;
return $this->_itemReviewed;
}

private $_ratingCount;
Expand Down
2 changes: 1 addition & 1 deletion core/web/jsonld/EventTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getComposer()
*/
public function setComposer($composer)
{
ObjectHelper::isInstanceOf($author, [Organization::class, PersonInterface::class]);
ObjectHelper::isInstanceOf($composer, [Organization::class, PersonInterface::class]);

$this->_composer = $composer;
return $this;
Expand Down
1 change: 1 addition & 0 deletions core/web/jsonld/GeoCoordinates.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public function typeDefintion()
public function setAddress(PostalAddress $address)
{
$this->_address = $address;
return $this;
}

/**
Expand Down
1 change: 1 addition & 0 deletions core/web/jsonld/MediaObjectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getContentUrl()
public function setEmbedUrl(UrlValue $url)
{
$this->_embedUrl = $url->getValue();
return $this;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
parameters:
level: 0
paths:
- src
- core
excludePaths:
- core/vendor
bootstrapFiles:
- vendor/yiisoft/yii2/Yii.php
tmpDir: .tmp
6 changes: 5 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/src'
__DIR__ . '/core'
]);

$rectorConfig->skip([
__DIR__ . '/core/vendor',
]);

// register a single rule
Expand Down
Loading

0 comments on commit b78e41d

Please sign in to comment.