Skip to content

Commit ae14a1f

Browse files
authored
Merge pull request #1635 from spryker/bugfix/cs
Fix CS using Spryker+Slevomat cs ruleset.
2 parents 6730eba + d739a69 commit ae14a1f

File tree

254 files changed

+9500
-6437
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

254 files changed

+9500
-6437
lines changed

.license

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* This file is part of the Propel package.
3+
* For the full copyright and license information, please view the LICENSE
4+
* file that was distributed with this source code.
5+
*
6+
* @license MIT License
7+
*/

composer.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"psr/log": "^1.0"
2828
},
2929
"require-dev": {
30+
"ext-pdo": "*",
31+
"ext-json": "*",
3032
"monolog/monolog": "^1.3",
3133
"phpstan/phpstan": "^0.12.4",
3234
"phpunit/phpunit": "^7.5.15",
@@ -44,11 +46,10 @@
4446
"bin/propel"
4547
],
4648
"scripts": {
47-
"cs-check": "phpcs -p -s --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/",
48-
"cs-fix": "phpcbf -p --standard=vendor/spryker/code-sniffer/Spryker/ruleset.xml src/",
49-
"stan": [
50-
"vendor/bin/phpstan analyze"
51-
]
49+
"cs-check": "phpcs -p -s --standard=config/phpcs.xml src/",
50+
"cs-fix": "phpcbf -p --standard=config/phpcs.xml src/",
51+
"stan": "vendor/bin/phpstan analyze",
52+
"stan-baseline": "vendor/bin/phpstan analyze --generate-baseline"
5253
},
5354
"extra": {
5455
"branch-alias": {

config/phpcs.xml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Propel">
3+
<description>
4+
Propel Coding Standard.
5+
6+
Extends Spryker+Slevomatik Coding Standard.
7+
</description>
8+
9+
<rule ref="vendor/spryker/code-sniffer/Spryker/ruleset.xml"/>
10+
11+
<exclude-pattern>*/templates/*</exclude-pattern>
12+
13+
<!-- exclude for now -->
14+
<rule ref="Spryker.Commenting.FileDocBlock">
15+
<severity>0</severity>
16+
</rule>
17+
<rule ref="Spryker.ControlStructures.NoInlineAssignment">
18+
<severity>0</severity>
19+
</rule>
20+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison">
21+
<severity>0</severity>
22+
</rule>
23+
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements">
24+
<severity>0</severity>
25+
</rule>
26+
27+
<rule ref="Spryker.Commenting.DocBlockReturnSelf">
28+
<severity>0</severity>
29+
</rule>
30+
31+
</ruleset>

phpstan-baseline.neon

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
includes:
22
- phpstan-baseline.neon
33
parameters:
4-
level: 5
4+
level: 6
55
checkGenericClassInNonGenericObjectType: false
66
checkMissingIterableValueType: false
77
paths:
@@ -25,4 +25,3 @@ parameters:
2525
-
2626
message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#"
2727
path: src/Propel/Common/Config/PropelConfiguration.php
28-
- '#PHPDoc tag @throws with type .+FileLoaderLoadException|.+LoaderLoadException is not subtype of Throwable#'

src/Propel/Common/Config/ConfigurationManager.php

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
use Propel\Common\Config\Exception\InvalidArgumentException;
1414
use Propel\Common\Config\Exception\InvalidConfigurationException;
1515
use Propel\Common\Config\Loader\DelegatingLoader;
16-
use Symfony\Component\Finder\Finder;
1716
use Symfony\Component\Config\Definition\Processor;
17+
use Symfony\Component\Finder\Finder;
1818

1919
/**
2020
* Class ConfigurationManager
@@ -25,7 +25,7 @@
2525
*/
2626
class ConfigurationManager
2727
{
28-
const CONFIG_FILE_NAME = 'propel';
28+
public const CONFIG_FILE_NAME = 'propel';
2929

3030
/**
3131
* Array of configuration values
@@ -37,8 +37,8 @@ class ConfigurationManager
3737
/**
3838
* Load and validate configuration values from a file.
3939
*
40-
* @param string|null $filename Configuration file name or directory in which resides the configuration file.
41-
* @param array $extraConf Array of configuration properties, to be merged with those loaded from file.
40+
* @param string|null $filename Configuration file name or directory in which resides the configuration file.
41+
* @param array $extraConf Array of configuration properties, to be merged with those loaded from file.
4242
* It's useful when passing configuration parameters from command line.
4343
*/
4444
public function __construct($filename = null, $extraConf = [])
@@ -61,7 +61,8 @@ public function get()
6161
* Return a specific section of the configuration array.
6262
* It ca be useful to get, in example, only 'generator' values.
6363
*
64-
* @param string $section the section to be returned
64+
* @param string $section the section to be returned
65+
*
6566
* @return array|null
6667
*/
6768
public function getSection($section)
@@ -81,9 +82,11 @@ public function getSection($section)
8182
* is expressed by:
8283
* <code>'database.adapter.mysql.tableType</code>
8384
*
84-
* @param string $name The name of property, expressed as a dot separated level hierarchy
85+
* @param string $name The name of property, expressed as a dot separated level hierarchy
86+
*
8587
* @throws \Propel\Common\Config\Exception\InvalidArgumentException
86-
* @return mixed The configuration property
88+
*
89+
* @return mixed The configuration property
8790
*/
8891
public function getConfigProperty($name)
8992
{
@@ -107,12 +110,13 @@ public function getConfigProperty($name)
107110
* Return an array of parameters relative to configured connections, for `runtime` or `generator` section.
108111
* It's useful for \Propel\Generator\Command\ConfigConvertCommand class
109112
*
110-
* @param string $section `runtime` or `generator` section
113+
* @param string $section `runtime` or `generator` section
114+
*
111115
* @return array|null
112116
*/
113117
public function getConnectionParametersArray($section = 'runtime')
114118
{
115-
if (!in_array($section, ['runtime', 'generator'])) {
119+
if (!in_array($section, ['runtime', 'generator'], true)) {
116120
return null;
117121
}
118122

@@ -132,8 +136,9 @@ public function getConnectionParametersArray($section = 'runtime')
132136
* Only one configuration file is supposed to be found.
133137
* This method also looks for a '.dist' configuration file and loads it.
134138
*
135-
* @param string|null $fileName Configuration file name or directory in which resides the configuration file.
139+
* @param string|null $fileName Configuration file name or directory in which resides the configuration file.
136140
* @param array|null $extraConf Array of configuration properties, to be merged with those loaded from file.
141+
*
137142
* @return void
138143
*/
139144
protected function load($fileName, $extraConf)
@@ -144,19 +149,19 @@ protected function load($fileName, $extraConf)
144149
$fileName = self::CONFIG_FILE_NAME;
145150
}
146151

147-
if (null === $extraConf) {
152+
if ($extraConf === null) {
148153
$extraConf = [];
149154
}
150155

151-
if (static::CONFIG_FILE_NAME === $fileName) {
156+
if ($fileName === static::CONFIG_FILE_NAME) {
152157
$files = $this->getFiles($dirs, $fileName);
153158
$distFiles = $this->getFiles($dirs, $fileName, true);
154159

155160
$numFiles = count($files);
156161
$numDistFiles = count($distFiles);
157162

158163
//allow to load only .dist file
159-
if (0 === $numFiles && 1 === $numDistFiles) {
164+
if ($numFiles === 0 && $numDistFiles === 1) {
160165
$files = $distFiles;
161166
$numFiles = 1;
162167
}
@@ -171,21 +176,22 @@ protected function load($fileName, $extraConf)
171176
$fileName = $file->getPathName();
172177
}
173178

174-
$this->config = array_replace_recursive($this->loadFile($fileName.'.dist'), $this->loadFile($fileName), $extraConf);
179+
$this->config = array_replace_recursive($this->loadFile($fileName . '.dist'), $this->loadFile($fileName), $extraConf);
175180
}
176181

177182
/**
178183
* Validate the configuration array via Propel\Common\Config\PropelConfiguration class
179184
* and add default values.
180185
*
181-
* @param array $extraConf Extra configuration to merge before processing. It's useful when a child class overwrite
186+
* @param array|null $extraConf Extra configuration to merge before processing. It's useful when a child class overwrite
182187
* the constructor to pass a built-in array of configuration, without load it from file. I.e.
183188
* Propel\Generator\Config\QuickGeneratorConfig class.
189+
*
184190
* @return void
185191
*/
186192
protected function process($extraConf = null)
187193
{
188-
if (null === $extraConf && count($this->config) <= 0) {
194+
if ($extraConf === null && count($this->config) <= 0) {
189195
return;
190196
}
191197

@@ -205,9 +211,11 @@ protected function process($extraConf = null)
205211
/**
206212
* Return an array of configuration files in the $dirs directories
207213
*
208-
* @param array $dirs The directories where to find the configuration files
214+
* @param array $dirs The directories where to find the configuration files
209215
* @param string $fileName The name of the file
210-
* @param bool $dist If search .dist files
216+
* @param bool $dist If search .dist files
217+
*
218+
* @throws \Propel\Common\Config\Exception\InvalidArgumentException
211219
*
212220
* @return array
213221
*/
@@ -216,7 +224,7 @@ private function getFiles($dirs, $fileName, $dist = false)
216224
$finder = new Finder();
217225
$fileName .= '.{php,inc,ini,properties,yaml,yml,xml,json}';
218226

219-
if (true === $dist) {
227+
if ($dist === true) {
220228
$fileName .= '.dist';
221229
}
222230

@@ -236,7 +244,6 @@ private function getFiles($dirs, $fileName, $dist = false)
236244
* @param string $fileName The configuration file
237245
*
238246
* @return array|mixed
239-
* @throws \Symfony\Component\Config\Exception\LoaderLoadException|\Symfony\Component\Config\Exception\FileLoaderLoadException
240247
*/
241248
private function loadFile($fileName)
242249
{
@@ -252,7 +259,8 @@ private function loadFile($fileName)
252259
/**
253260
* Return the directories where to find the configuration file.
254261
*
255-
* @param string|null $fileName
262+
* @param string|null $fileName
263+
*
256264
* @return array
257265
*/
258266
private function getDirs($fileName)
@@ -268,11 +276,11 @@ private function getDirs($fileName)
268276
}
269277

270278
$dirs[] = $currentDir;
271-
if (is_dir($currentDir.'/conf')) {
272-
$dirs[] = $currentDir.'/conf';
279+
if (is_dir($currentDir . '/conf')) {
280+
$dirs[] = $currentDir . '/conf';
273281
}
274-
if (is_dir($currentDir.'/config')) {
275-
$dirs[] = $currentDir.'/config';
282+
if (is_dir($currentDir . '/config')) {
283+
$dirs[] = $currentDir . '/config';
276284
}
277285

278286
return $dirs;
@@ -296,6 +304,8 @@ private function cleanupSlaveConnections()
296304
* If not defined, set `runtime` and `generator` connections, based on `database.connections` property.
297305
* Check if runtime and generator connections are correctly defined.
298306
*
307+
* @throws \Propel\Common\Config\Exception\InvalidConfigurationException
308+
*
299309
* @return void
300310
*/
301311
private function cleanupConnections()
@@ -314,14 +324,14 @@ private function cleanupConnections()
314324

315325
foreach ($this->config[$section]['connections'] as $connection) {
316326
if (!array_key_exists($connection, $this->config['database']['connections'])) {
317-
throw new InvalidConfigurationException("`$connection` isn't a valid configured connection (Section: propel.$section.connections). ".
318-
"Please, check your configured connections in `propel.database.connections` section of your configuration file.");
327+
throw new InvalidConfigurationException("`$connection` isn't a valid configured connection (Section: propel.$section.connections). " .
328+
'Please, check your configured connections in `propel.database.connections` section of your configuration file.');
319329
}
320330
}
321331

322332
if (!array_key_exists($defaultConnection = $this->config[$section]['defaultConnection'], $this->config['database']['connections'])) {
323-
throw new InvalidConfigurationException("`$defaultConnection` isn't a valid configured connection (Section: propel.$section.defaultConnection). ".
324-
"Please, check your configured connections in `propel.database.connections` section of your configuration file.");
333+
throw new InvalidConfigurationException("`$defaultConnection` isn't a valid configured connection (Section: propel.$section.defaultConnection). " .
334+
'Please, check your configured connections in `propel.database.connections` section of your configuration file.');
325335
}
326336
}
327337
}

src/Propel/Common/Config/Exception/InvalidArgumentException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace Propel\Common\Config\Exception;
1212

13-
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
13+
use InvalidArgumentException as CoreInvalidArgumentException;
14+
15+
class InvalidArgumentException extends CoreInvalidArgumentException implements ExceptionInterface
1416
{
1517
}

0 commit comments

Comments
 (0)