Skip to content

Commit

Permalink
Add PHPStan level 1 check with baseline until we can remove symf2.
Browse files Browse the repository at this point in the history
  • Loading branch information
dereuromark committed Jul 7, 2020
1 parent c8a40ff commit 584c40b
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 7 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,6 @@ jobs:

allow_failures:
- php: nightly
- name: "Checks"

fast_finish: true

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
],
"scripts": {
"stan": [
"vendor/bin/phpstan analyze -c tests/phpstan.neon"
"vendor/bin/phpstan analyze"
]
},
"extra": {
Expand Down
6 changes: 6 additions & 0 deletions tests/phpstan.neon → phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
includes:
- phpstan-baseline.neon
parameters:
level: 1
paths:
Expand All @@ -12,5 +14,9 @@ parameters:
- '%rootDir%/../../../src/Propel/Generator/Behavior/Delegate/templates/*'
- '%rootDir%/../../../src/Propel/Generator/Behavior/Sortable/templates/*'
- '%rootDir%/../../../src/Propel/Generator/Behavior/NestedSet/templates/*'
- '%rootDir%/../../../src/Propel/Runtime/Connection/PdoConnection.php'
- '%rootDir%/../../../src/Propel/Generator/Command/Helper/ConsoleHelper.php'
- '%rootDir%/../../../src/Propel/Generator/Command/InitCommand.php'
ignoreErrors:
- '#Call to an undefined method .+Collection::.+Array\(\)#'
- '#Class .+TreeBuilder constructor invoked with 0 parameters, 1-3 required#'
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,84 @@
*/
class VersionableBehaviorObjectBuilderModifier
{
/**
* @var \Propel\Generator\Model\Behavior
*/
protected $behavior;
/**
* @var \Propel\Generator\Model\Table
*/
protected $table;
/**
* @var \Propel\Generator\Builder\Om\AbstractOMBuilder
*/
protected $builder;
/**
* @var string
*/
protected $objectClassName;
protected $queryClassName;

/**
* @param \Propel\Generator\Model\Behavior $behavior
*/
public function __construct($behavior)
{
$this->behavior = $behavior;
$this->table = $behavior->getTable();
}

/**
* @param string $key
*
* @return array
*/
protected function getParameter($key)
{
return $this->behavior->getParameter($key);
}

/**
* @param string $name
*
* @return string
*/
protected function getColumnAttribute($name = 'version_column')
{
return strtolower($this->behavior->getColumnForParameter($name)->getName());
}

/**
* @param string $name
*
* @return string
*/
protected function getColumnPhpName($name = 'version_column')
{
return $this->behavior->getColumnForParameter($name)->getPhpName();
}

/**
* @return string
*/
protected function getVersionQueryClassName()
{
return $this->builder->getClassNameFromBuilder($this->builder->getNewStubQueryBuilder($this->behavior->getVersionTable()));
}

/**
* @return string
*/
protected function getActiveRecordClassName()
{
return $this->builder->getObjectClassName();
}

/**
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
*
* @return void
*/
protected function setBuilder($builder)
{
$this->builder = $builder;
Expand Down Expand Up @@ -83,6 +124,11 @@ protected function getColumnSetter($name = 'version_column')
return 'set' . $this->getColumnPhpName($name);
}

/**
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
*
* @return string
*/
public function preSave($builder)
{
$script = "if (\$this->isVersioningNecessary()) {
Expand All @@ -101,13 +147,23 @@ public function preSave($builder)
return $script;
}

/**
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
*
* @return string
*/
public function postSave($builder)
{
return "if (isset(\$createVersion)) {
\$this->addVersion(\$con);
}";
}

/**
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
*
* @return string
*/
public function postDelete($builder)
{
$this->builder = $builder;
Expand All @@ -121,6 +177,11 @@ public function postDelete($builder)
}
}

/**
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
*
* @return string
*/
public function objectAttributes($builder)
{
$script = '';
Expand All @@ -130,6 +191,11 @@ public function objectAttributes($builder)
return $script;
}

/**
* @param string $script
*
* @return void
*/
protected function addEnforceVersionAttribute(&$script)
{
$script .= "
Expand All @@ -141,6 +207,11 @@ protected function addEnforceVersionAttribute(&$script)
";
}

/**
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
*
* @return string
*/
public function objectMethods($builder)
{
$this->setBuilder($builder);
Expand All @@ -166,6 +237,11 @@ public function objectMethods($builder)
return $script;
}

/**
* @param string $script
*
* @return void
*/
protected function addVersionSetter(&$script)
{
$script .= "
Expand All @@ -182,6 +258,11 @@ public function setVersion(\$v)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addVersionGetter(&$script)
{
$script .= "
Expand All @@ -197,6 +278,11 @@ public function getVersion()
";
}

/**
* @param string $script
*
* @return void
*/
protected function addEnforceVersioning(&$script)
{
$objectClass = $this->builder->getStubObjectBuilder()->getClassname();
Expand All @@ -215,6 +301,11 @@ public function enforceVersioning()
";
}

/**
* @param string $script
*
* @return void
*/
protected function addIsVersioningNecessary(&$script)
{
$queryClassName = $this->builder->getQueryClassName();
Expand Down Expand Up @@ -298,6 +389,11 @@ public function isVersioningNecessary(ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addAddVersion(&$script)
{
$versionTable = $this->behavior->getVersionTable();
Expand Down Expand Up @@ -366,6 +462,11 @@ public function addVersion(ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addToVersion(&$script)
{
$ARclassName = $this->getActiveRecordClassName();
Expand All @@ -391,6 +492,11 @@ public function toVersion(\$versionNumber, ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addPopulateFromVersion(&$script)
{
$ARclassName = $this->getActiveRecordClassName();
Expand All @@ -414,7 +520,8 @@ public function populateFromVersion(\$version, \$con = null, &\$loadedObjects =
$script .= "
\$loadedObjects['{$ARclassName}'][\$version->get{$primaryKeyName}()][\$version->get{$versionColumnName}()] = \$this;";

foreach ($this->table->getColumns() as $col) {
$columns = $this->table->getColumns();
foreach ($columns as $col) {
$script .= "
\$this->set" . $col->getPhpName() . "(\$version->get" . $col->getPhpName() . "());";
}
Expand Down Expand Up @@ -492,6 +599,11 @@ public function populateFromVersion(\$version, \$con = null, &\$loadedObjects =
";
}

/**
* @param string $script
*
* @return void
*/
protected function addGetLastVersionNumber(&$script)
{
$script .= "
Expand All @@ -517,6 +629,11 @@ public function getLastVersionNumber(ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addIsLastVersion(&$script)
{
$script .= "
Expand All @@ -534,6 +651,11 @@ public function isLastVersion(ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addGetOneVersion(&$script)
{
$versionARClassName = $this->builder->getClassNameFromBuilder($this->builder->getNewStubObjectBuilder($this->behavior->getVersionTable()));
Expand All @@ -556,6 +678,11 @@ public function getOneVersion(\$versionNumber, ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addGetAllVersions(&$script)
{
$versionTable = $this->behavior->getVersionTable();
Expand Down Expand Up @@ -583,6 +710,11 @@ public function getAllVersions(ConnectionInterface \$con = null)
";
}

/**
* @param string $script
*
* @return void
*/
protected function addComputeDiff(&$script)
{
$script .= "
Expand Down Expand Up @@ -649,6 +781,11 @@ protected function computeDiff(\$fromVersion, \$toVersion, \$keys = 'columns', \
";
}

/**
* @param string $script
*
* @return void
*/
protected function addCompareVersion(&$script)
{
$script .= "
Expand Down Expand Up @@ -679,6 +816,11 @@ public function compareVersion(\$versionNumber, \$keys = 'columns', ConnectionIn
";
}

/**
* @param string $script
*
* @return void
*/
protected function addCompareVersions(&$script)
{
$script .= "
Expand Down Expand Up @@ -710,6 +852,11 @@ public function compareVersions(\$fromVersionNumber, \$toVersionNumber, \$keys =
";
}

/**
* @param string $script
*
* @return void
*/
protected function addGetLastVersions(&$script)
{
$plural = true;
Expand Down
Loading

0 comments on commit 584c40b

Please sign in to comment.