Skip to content

Commit c6c3d37

Browse files
committed
More PHPStan fixes.
1 parent 1a67ef7 commit c6c3d37

38 files changed

+141
-71
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@
4848
"scripts": {
4949
"cs-check": "phpcs -p -s --standard=config/phpcs.xml src/",
5050
"cs-fix": "phpcbf -p --standard=config/phpcs.xml src/",
51-
"stan": [
52-
"vendor/bin/phpstan analyze"
53-
]
51+
"stan": "vendor/bin/phpstan analyze",
52+
"stan-baseline": "vendor/bin/phpstan analyze --generate-baseline"
5453
},
5554
"extra": {
5655
"branch-alias": {

phpstan-baseline.neon

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

src/Propel/Common/Config/Loader/FileLoader.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,14 @@ public function resolveParams(array $configuration)
9090
*
9191
* @throws \Propel\Common\Config\Exception\InputOutputException If the path isnot readable
9292
*
93-
* @return array|string
93+
* @return string
9494
*/
9595
protected function getPath($file)
9696
{
9797
$path = $this->locator->locate($file);
98+
if (!is_string($path)) {
99+
throw new InputOutputException("$file must return a single path.");
100+
}
98101

99102
if (!is_readable($path)) {
100103
throw new InputOutputException("You don't have permissions to access configuration file $file.");

src/Propel/Generator/Behavior/ConcreteInheritance/ConcreteInheritanceBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ public function syncParentToChild($parentClass \$parent)
290290
if ($columns === true) {
291291
$columns = $parentTable->getColumns();
292292
} else {
293-
$columnNames = $columns;
293+
$columnNames = $columns ?: [];
294294
$columns = [];
295295
foreach ($columnNames as $columnName) {
296296
$column = $this->getTable()->getColumn($columnName);

src/Propel/Generator/Builder/Om/ObjectBuilder.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ protected function getDefaultValueString(Column $column)
198198
if (!in_array($val, $valueSet)) {
199199
throw new EngineException(sprintf('Default Value "%s" is not among the enumerated values', $val));
200200
}
201-
$defaultValue = array_search($val, $valueSet);
201+
$defaultValue = (string)array_search($val, $valueSet);
202202
} elseif ($column->isSetType()) {
203-
$defaultValue = SetColumnConverter::convertToInt($val, $column->getValueSet());
203+
$defaultValue = (string)SetColumnConverter::convertToInt($val, $column->getValueSet());
204204
} elseif ($column->isPhpPrimitiveType()) {
205205
settype($val, $column->getPhpType());
206206
$defaultValue = var_export($val, true);
@@ -4186,9 +4186,9 @@ protected function addFKAccessor(&$script, ForeignKey $fk)
41864186
if ($rightValueOrColumn instanceof Column) {
41874187
$localColumns[$rightValueOrColumn->getPosition()] = '$this->' . $clo;
41884188

4189-
if ($cptype == 'int' || $cptype == 'float' || $cptype == 'double') {
4189+
if ($cptype === 'int' || $cptype === 'float' || $cptype === 'double') {
41904190
$conditional .= $and . '$this->' . $clo . ' != 0';
4191-
} elseif ($cptype == 'string') {
4191+
} elseif ($cptype === 'string') {
41924192
$conditional .= $and . '($this->' . $clo . ' !== "" && $this->' . $clo . ' !== null)';
41934193
} else {
41944194
$conditional .= $and . '$this->' . $clo . ' !== null';
@@ -6510,7 +6510,7 @@ protected function addDoInsertBodyRaw()
65106510
}
65116511

65126512
// if non auto-increment but using sequence, get the id first
6513-
if (!$platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() == 'native') {
6513+
if (!$platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() === 'native') {
65146514
$column = $table->getFirstPrimaryKeyColumn();
65156515
if (!$column) {
65166516
throw new PropelException('Cannot find primary key column in table `' . $table->getName() . '`.');
@@ -6571,7 +6571,7 @@ protected function addDoInsertBodyRaw()
65716571
";
65726572

65736573
// if auto-increment, get the id after
6574-
if ($platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() == 'native') {
6574+
if ($platform->isNativeIdMethodAutoIncrement() && $table->getIdMethod() === 'native') {
65756575
$script .= "
65766576
try {";
65776577
$script .= $platform->getIdentifierPhp('$pk', '$con', $primaryKeyMethodInfo);

src/Propel/Generator/Builder/Om/TableMapBuilder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ public function initialize()
517517
\$this->setIdentifierQuoting(" . ($table->isIdentifierQuotingEnabled() ? 'true' : 'false') . ");
518518
\$this->setClassName('" . addslashes($this->getStubObjectBuilder()->getFullyQualifiedClassName()) . "');
519519
\$this->setPackage('" . parent::getPackage() . "');";
520-
if ($table->getIdMethod() == 'native') {
520+
if ($table->getIdMethod() === 'native') {
521521
$script .= "
522522
\$this->setUseIdGenerator(true);";
523523
} else {
@@ -696,7 +696,7 @@ public function getBehaviors()
696696
/**
697697
* Adds the PHP code to return a instance pool key for the passed-in primary key variable names.
698698
*
699-
* @param array $pkphp An array of PHP var names / method calls representing complete pk.
699+
* @param string[]|string $pkphp An array of PHP var names / method calls representing complete pk.
700700
*
701701
* @return string
702702
*/

src/Propel/Generator/Builder/Util/PropelTemplate.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
class PropelTemplate
2222
{
2323
/**
24-
* @var string
24+
* @var string|null
2525
*/
2626
protected $template;
2727

2828
/**
29-
* @var string
29+
* @var string|null
3030
*/
3131
protected $templateFile;
3232

@@ -75,7 +75,7 @@ public function setTemplateFile($filePath)
7575
*
7676
* @param array $vars An associative array of arguments to be rendered
7777
*
78-
* @throws InvalidArgumentException
78+
* @throws \Propel\Generator\Exception\InvalidArgumentException
7979
*
8080
* @return string The rendered template
8181
*/

src/Propel/Generator/Command/AbstractCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ abstract class AbstractCommand extends Command
3535
protected $filesystem;
3636

3737
/**
38-
* @inheritDoc
38+
* {@inheritDoc}
39+
*
40+
* @return void
3941
*/
4042
protected function configure()
4143
{

src/Propel/Generator/Command/Console/Input/ArrayInput.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ public function __toString()
133133
}
134134

135135
/**
136-
* @inheritDoc
136+
* {@inheritDoc}
137+
*
138+
* @return void
137139
*/
138140
protected function parse()
139141
{
@@ -177,6 +179,7 @@ private function addShortOption(string $shortcut, $value)
177179
* @param mixed|null $value
178180
*
179181
* @throws \Symfony\Component\Console\Exception\InvalidOptionException When a required value is missing
182+
*
180183
* @return void
181184
*/
182185
private function addLongOption(string $name, $value)

src/Propel/Generator/Command/DatabaseReverseCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
5656
{
5757
$configOptions = [];
5858

59-
$connection = $input->getArgument('connection');
59+
$connection = (string)$input->getArgument('connection');
6060
if (strpos($connection, ':') === false) {
6161
//treat it as connection name
6262
$configOptions['propel']['reverse']['connection'] = $connection;

0 commit comments

Comments
 (0)