Skip to content

Commit

Permalink
Upgrade PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
oojacoboo committed Dec 5, 2021
1 parent 073d2bc commit 18ab6fd
Show file tree
Hide file tree
Showing 22 changed files with 83 additions and 111 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"ext-pdo": "*",
"ext-json": "*",
"monolog/monolog": "^1.3",
"phpstan/phpstan": "^0.12.97",
"phpstan/phpstan": "^1.2",
"phpunit/phpunit": "^8.0.0||^9.0.0",
"spryker/code-sniffer": "^0.15.6",
"psalm/phar": "4.9.3",
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
checkMissingIterableValueType: false
paths:
- '%rootDir%/../../../src/'
excludes_analyse:
excludePaths:
- '%rootDir%/../../../src/Propel/Generator/Command/templates/*'
- '%rootDir%/../../../src/Propel/Generator/Behavior/AggregateColumn/templates/*'
- '%rootDir%/../../../src/Propel/Generator/Behavior/AggregateMultipleColumns/templates/*'
Expand Down
4 changes: 3 additions & 1 deletion src/Propel/Common/Config/Loader/IniFileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class IniFileLoader extends FileLoader
*
* @var string
*/
private $nestSeparator = '.';
private string $nestSeparator = '.';

/**
* Returns true if this class supports the given resource.
Expand Down Expand Up @@ -80,6 +80,7 @@ private function parse(array $data): array

foreach ($data as $section => $value) {
if (is_array($value)) {
// @phpstan-ignore-next-line
$sections = explode($this->nestSeparator, $section);
$config = array_merge_recursive($config, $this->buildNestedSection($sections, $value));
} else {
Expand Down Expand Up @@ -149,6 +150,7 @@ private function parseKey(string $key, $rawValue, array &$config): void
$value = (float)$rawValue;
}
}
// @phpstan-ignore-next-line
$subKeys = explode($this->nestSeparator, $key);
$subConfig = &$config;
$lastIndex = count($subKeys) - 1;
Expand Down
2 changes: 2 additions & 0 deletions src/Propel/Common/Config/XmlToArrayConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ protected static function simpleXmlToArray(SimpleXMLElement $xml): array

// if it's not an array, then it was empty, thus a value/string
if ($child === []) {
// @phpstan-ignore-next-line
$child = static::getConvertedXmlValue($v);
}

Expand All @@ -104,6 +105,7 @@ protected static function simpleXmlToArray(SimpleXMLElement $xml): array
if (is_string($child)) {
$child = [];
}
// @phpstan-ignore-next-line
$child[$ak] = static::getConvertedXmlValue($av);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class AggregateMultipleColumnsBehavior extends Behavior
*/
public static function resetInsertedAggregationNames(): void
{
// @phpstan-ignore-next-line
static::$insertedAggregationNames = [];
}

Expand Down Expand Up @@ -93,10 +94,13 @@ private function buildAggregationName(): string
$foreignTableName = $this->getForeignTable()->getPhpName();
$baseAggregationName = 'AggregatedColumnsFrom' . $foreignTableName;
$tableName = $this->getTable()->getPhpName();
// @phpstan-ignore-next-line
if (!array_key_exists($tableName, static::$insertedAggregationNames)) {
// @phpstan-ignore-next-line
static::$insertedAggregationNames[$tableName] = [];
}

// @phpstan-ignore-next-line
$existingNames = &static::$insertedAggregationNames[$tableName];
if (!in_array($baseAggregationName, $existingNames)) {
$existingNames[] = $baseAggregationName;
Expand Down
64 changes: 35 additions & 29 deletions src/Propel/Generator/Builder/DataModelBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

namespace Propel\Generator\Builder;

use Propel\Common\Pluralizer\PluralizerInterface;
use Propel\Generator\Builder\Om\AbstractObjectBuilder;
use Propel\Generator\Builder\Om\AbstractOMBuilder;
use Propel\Generator\Builder\Om\MultiExtendObjectBuilder;
use Propel\Generator\Builder\Om\ObjectBuilder;
use Propel\Generator\Builder\Om\TableMapBuilder;
use Propel\Generator\Config\GeneratorConfigInterface;
use Propel\Generator\Model\Inheritance;
use Propel\Generator\Model\Table;
Expand All @@ -33,84 +39,84 @@ abstract class DataModelBuilder
*
* @var \Propel\Generator\Model\Table
*/
private $table;
private Table $table;

/**
* The generator config object holding build properties, etc.
*
* @var \Propel\Generator\Config\GeneratorConfigInterface
* @var \Propel\Generator\Config\GeneratorConfigInterface|null
*/
private $generatorConfig;
private ?GeneratorConfigInterface $generatorConfig = null;

/**
* An array of warning messages that can be retrieved for display.
*
* @var array string[]
*/
private $warnings = [];
private array $warnings = [];

/**
* Object builder class for current table.
*
* @var \Propel\Generator\Builder\Om\ObjectBuilder
* @var \Propel\Generator\Builder\Om\ObjectBuilder|null
*/
private $objectBuilder;
private ?ObjectBuilder $objectBuilder = null;

/**
* Stub Object builder class for current table.
*
* @var \Propel\Generator\Builder\Om\ObjectBuilder
* @var \Propel\Generator\Builder\Om\AbstractObjectBuilder|null
*/
private $stubObjectBuilder;
private ?AbstractObjectBuilder $stubObjectBuilder = null;

/**
* Query builder class for current table.
*
* @var \Propel\Generator\Builder\Om\ObjectBuilder
* @var \Propel\Generator\Builder\Om\AbstractOMBuilder|null
*/
private $queryBuilder;
private ?AbstractOMBuilder $queryBuilder = null;

/**
* Stub Query builder class for current table.
*
* @var \Propel\Generator\Builder\Om\ObjectBuilder
* @var \Propel\Generator\Builder\Om\AbstractOMBuilder|null
*/
private $stubQueryBuilder;
private ?AbstractOMBuilder $stubQueryBuilder = null;

/**
* TableMap builder class for current table.
*
* @var \Propel\Generator\Builder\Om\TableMapBuilder
* @var \Propel\Generator\Builder\Om\TableMapBuilder|null
*/
protected $tablemapBuilder;
protected ?TableMapBuilder $tablemapBuilder = null;

/**
* Stub Interface builder class for current table.
*
* @var \Propel\Generator\Builder\Om\ObjectBuilder
* @var \Propel\Generator\Builder\Om\AbstractOMBuilder|null
*/
private $interfaceBuilder;
private ?AbstractOMBuilder $interfaceBuilder = null;

/**
* Stub child object for current table.
*
* @var \Propel\Generator\Builder\Om\MultiExtendObjectBuilder
* @var \Propel\Generator\Builder\Om\MultiExtendObjectBuilder|null
*/
private $multiExtendObjectBuilder;
private ?MultiExtendObjectBuilder $multiExtendObjectBuilder = null;

/**
* The Pluralizer class to use.
*
* @var \Propel\Common\Pluralizer\PluralizerInterface
* @var \Propel\Common\Pluralizer\PluralizerInterface|null
*/
private $pluralizer;
private ?PluralizerInterface $pluralizer = null;

/**
* The platform class
*
* @var \Propel\Generator\Platform\PlatformInterface
*/
protected $platform;
protected ?PlatformInterface $platform = null;

/**
* Creates new instance of DataModelBuilder subclass.
Expand Down Expand Up @@ -155,9 +161,9 @@ public function getObjectBuilder()
/**
* Returns new or existing stub Object builder class for this table.
*
* @return \Propel\Generator\Builder\Om\ObjectBuilder
* @return \Propel\Generator\Builder\Om\AbstractObjectBuilder|null
*/
public function getStubObjectBuilder()
public function getStubObjectBuilder(): ?AbstractObjectBuilder
{
if (!isset($this->stubObjectBuilder)) {
/** @var \Propel\Generator\Builder\Om\ObjectBuilder $builder */
Expand All @@ -171,9 +177,9 @@ public function getStubObjectBuilder()
/**
* Returns new or existing Query builder class for this table.
*
* @return \Propel\Generator\Builder\Om\ObjectBuilder
* @return \Propel\Generator\Builder\Om\AbstractOMBuilder|null
*/
public function getQueryBuilder()
public function getQueryBuilder(): ?AbstractOMBuilder
{
if (!isset($this->queryBuilder)) {
/** @var \Propel\Generator\Builder\Om\ObjectBuilder $builder */
Expand All @@ -187,9 +193,9 @@ public function getQueryBuilder()
/**
* Returns new or existing stub Query builder class for this table.
*
* @return \Propel\Generator\Builder\Om\ObjectBuilder
* @return \Propel\Generator\Builder\Om\AbstractOMBuilder|null
*/
public function getStubQueryBuilder()
public function getStubQueryBuilder(): ?AbstractOMBuilder
{
if (!isset($this->stubQueryBuilder)) {
/** @var \Propel\Generator\Builder\Om\ObjectBuilder $builder */
Expand Down Expand Up @@ -219,9 +225,9 @@ public function getTableMapBuilder()
/**
* Returns new or existing stub Interface builder class for this table.
*
* @return \Propel\Generator\Builder\Om\ObjectBuilder
* @return \Propel\Generator\Builder\Om\AbstractOMBuilder|null
*/
public function getInterfaceBuilder()
public function getInterfaceBuilder(): ?AbstractOMBuilder
{
if (!isset($this->interfaceBuilder)) {
/** @var \Propel\Generator\Builder\Om\ObjectBuilder $builder */
Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Generator/Builder/Om/ClassTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class ClassTools
/**
* Gets just classname, given a dot-path to class.
*
* @param string $qualifiedName
* @param string|null $qualifiedName
*
* @return string
* @return string|null
*/
public static function classname($qualifiedName)
public static function classname(?string $qualifiedName): ?string
{
if ($qualifiedName === null) {
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Builder/Util/PropelTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function render($vars = [])

extract($vars);
ob_start();
ob_implicit_flush(0);
ob_implicit_flush(false);

try {
if ($this->templateFile !== null) {
Expand Down
18 changes: 5 additions & 13 deletions src/Propel/Generator/Builder/Util/SchemaReader.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Propel\Generator\Model\Schema;
use Propel\Generator\Model\Unique;
use Propel\Generator\Platform\PlatformInterface;
use XMLParser;

/**
* A class that is used to parse an input xml schema file and creates a Schema
Expand All @@ -36,9 +37,9 @@ class SchemaReader
private $schema;

/**
* @var resource
* @var \XMLParser|null
*/
private $parser;
private ?XMLParser $parser = null;

/**
* @var \Propel\Generator\Model\Database
Expand Down Expand Up @@ -105,13 +106,6 @@ class SchemaReader
*/
private $currParameterListCollector;

/**
* @deprecated Unused.
*
* @var string
*/
private $encoding;

/**
* Two-dimensional array,
* first dimension is for schemas(key is the path to the schema file),
Expand All @@ -126,13 +120,11 @@ class SchemaReader
*
* @param \Propel\Generator\Platform\PlatformInterface|null $defaultPlatform The default database platform for the application.
* @param string|null $defaultPackage the default PHP package used for the om
* @param string $encoding The database encoding.
*/
public function __construct(?PlatformInterface $defaultPlatform = null, $defaultPackage = null, $encoding = 'iso-8859-1')
public function __construct(?PlatformInterface $defaultPlatform = null, $defaultPackage = null)
{
$this->schema = new Schema($defaultPlatform);
$this->defaultPackage = $defaultPackage;
$this->encoding = $encoding;
}

/**
Expand Down Expand Up @@ -191,7 +183,7 @@ public function parseString($xmlString, $xmlFile = null)
$this->parser = xml_parser_create();
xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
xml_set_object($this->parser, $this);
xml_set_element_handler($this->parser, 'startElement', 'endElement');
xml_set_element_handler($this->parser, [$this, 'startElement'], [$this, 'endElement']);
if (!xml_parse($this->parser, $xmlString)) {
throw new SchemaException(
sprintf(
Expand Down
2 changes: 2 additions & 0 deletions src/Propel/Generator/Model/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ public function setSchema($schema)
}
} elseif ($oldSchema) {
if (strpos($k, $schemaDelimiter) !== false) {
// @phpstan-ignore-next-line
$array[explode($schemaDelimiter, $k)[1]] = $v;
unset($array[$k]);
}
Expand Down Expand Up @@ -891,6 +892,7 @@ public function doFinalInitialization()
}

// execute table behaviors (may add new tables and new behaviors)
// @phpstan-ignore-next-line
while ($behavior = $this->getNextTableBehavior()) {
$behavior->getTableModifier()->modifyTable();
$behavior->setTableModified(true);
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Model/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ public function replaceDefaultValue(?ColumnDefaultValue $value = null)
/**
* Returns the SQL type.
*
* @return string
* @return string|null
*/
public function getSqlType()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Propel/Generator/Model/MappingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected function getDefaultValueForArray(string $stringValue)
}

$value = implode(' | ', $values);
if (empty($value) || $value === ' | ') {
if ($value === ' | ') {
return null;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Propel/Generator/Model/PhpNameGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ class PhpNameGenerator implements NameGeneratorInterface
*
* @see NameGenerator
*
* @param string[] $inputs List expected to contain two (optional: three) parameters,
* @param (string|null)[] $inputs List expected to contain two (optional: three) parameters,
* element 0 contains name to convert, element 1 contains method for conversion,
* optional element 2 contains prefix to be striped from name
*
* @return string The generated name.
* @return string|null The generated name.
*/
public function generateName($inputs)
public function generateName($inputs): ?string
{
$schemaName = $inputs[0];
$method = $inputs[1];
Expand Down
Loading

0 comments on commit 18ab6fd

Please sign in to comment.