diff --git a/generator/lib/builder/util/XmlToAppData.php b/generator/lib/builder/util/XmlToAppData.php index 3bd5abf3a..fb1f7924c 100644 --- a/generator/lib/builder/util/XmlToAppData.php +++ b/generator/lib/builder/util/XmlToAppData.php @@ -121,6 +121,7 @@ public function parseString($xmlString, $xmlFile = null) xml_set_object($parser, $this); xml_set_element_handler($parser, 'startElement', 'endElement'); if (!xml_parse($parser, $xmlString)) { + /** @psalm-suppress PossiblyNullArgument */ throw new Exception(sprintf( 'XML error: %s at line %d', xml_error_string(xml_get_error_code($parser)), diff --git a/psalm-baseline.xml b/psalm-baseline.xml index e0c50254e..9ac567aae 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $script @@ -6975,18 +6975,10 @@ getPrimaryKeyColumns getPrimaryKeyColumns - - !$this->getPrimaryCriteria() - !$this->getPrimaryCriteria() - !$this->getPrimaryCriteria() - !$this->getPrimaryCriteria() - !$this->getPrimaryCriteria() + $failSilently is_array($values) - - ModelCriteria - $this->getCriterionForClause($clause, $value, $bindingType) @@ -6998,16 +6990,10 @@ Integer TableMap - + new $class() new $formatter() - new $secondaryCriteriaClass() - - $secondaryCriteria - $this->add($this->getRealColumnName($column), $value, $comparison) - $this->addUsingOperator($this->getAliasedColName($column), $value, $operator) - $affectedRows $affectedRows @@ -7017,7 +7003,7 @@ $name $values - + $currentAlias $defaultFormatterClass $formatter @@ -7029,7 +7015,6 @@ $modelPeerName $originalModelAlias $previousJoin - $primaryCriteria $replacedColumns $select $useAliasInSQL @@ -7045,11 +7030,6 @@ setPreviousJoin setPrimaryCriteria - - ModelCriteria - ModelCriteria - ModelCriteria - strrpos($colName, '.') diff --git a/runtime/lib/query/Criteria.php b/runtime/lib/query/Criteria.php index eacc5fbf2..87871b91f 100644 --- a/runtime/lib/query/Criteria.php +++ b/runtime/lib/query/Criteria.php @@ -298,10 +298,8 @@ public function getMap() * Brings this criteria back to its initial state, so that it * can be reused as if it was new. Except if the criteria has grown in * capacity, it is left at the current capacity. - * - * @return void */ - public function clear() + public function clear(): static { $this->map = []; $this->namedCriterions = []; @@ -326,6 +324,7 @@ public function clear() $this->primaryTableName = null; $this->queryComment = null; + return $this; } /** @@ -341,7 +340,7 @@ public function clear() * * If the name already exists, it is replaced by the new clause. * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addAsColumn($name, $clause) { @@ -380,7 +379,7 @@ public function getColumnForAs($as) * @param string $alias * @param string $table * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addAlias($alias, $table) { @@ -394,7 +393,7 @@ public function addAlias($alias, $table) * * @param string $alias * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function removeAlias($alias) { @@ -734,7 +733,7 @@ public function get($key) * @param string $key * @param mixed $value * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function put($key, $value) { @@ -785,7 +784,7 @@ public function putAll($t) * @param mixed $value * @param string $comparison A String. * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function add($critOrColumn, $value = null, $comparison = null) { @@ -820,7 +819,7 @@ public function add($critOrColumn, $value = null, $comparison = null) * @param mixed $value * @param string $comparison A String. * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addCond($name, $p1, $value = null, $comparison = null) { @@ -836,7 +835,7 @@ public function addCond($name, $p1, $value = null, $comparison = null) * @param string $operator logical operator, either Criteria::LOGICAL_AND, or Criteria::LOGICAL_OR * @param string $name optional name to combine the criterion later * - * @return Criteria + * @return static * * @throws PropelException */ @@ -879,7 +878,7 @@ public function combine($criterions = [], $operator = self::LOGICAL_AND, $name = * among Criteria::INNER_JOIN, Criteria::LEFT_JOIN, * and Criteria::RIGHT_JOIN * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addJoin($left, $right, $joinType = null) { @@ -937,7 +936,7 @@ public function addJoin($left, $right, $joinType = null) * @param array $conditions An array of conditions, each condition being an array (left, right, operator) * @param string $joinType A String with the join operator. Defaults to an implicit join. * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addMultipleJoin($conditions, $joinType = null) { @@ -995,7 +994,7 @@ public function addMultipleJoin($conditions, $joinType = null) * * @param Join $join A join object * - * @return Criteria A modified Criteria object + * @return static A modified Criteria object */ public function addJoinObject(Join $join) { @@ -1030,7 +1029,7 @@ public function getJoins() * @param Criteria $subQueryCriteria Criteria to build the subquery from * @param string $alias alias for the subQuery * - * @return Criteria this modified Criteria object (Fluid API) + * @return static this modified Criteria object (Fluid API) */ public function addSelectQuery(Criteria $subQueryCriteria, $alias = null) { @@ -1100,7 +1099,7 @@ public function forgeSelectQueryAlias() /** * Adds "ALL" modifier to the SQL statement. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setAll() { @@ -1113,7 +1112,7 @@ public function setAll() /** * Adds "DISTINCT" modifier to the SQL statement. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setDistinct() { @@ -1129,7 +1128,7 @@ public function setDistinct() * * @param string $modifier The modifier to add * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function addSelectModifier($modifier) { @@ -1147,7 +1146,7 @@ public function addSelectModifier($modifier) * * @param string $modifier The modifier to add * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function removeSelectModifier($modifier) { @@ -1173,7 +1172,7 @@ public function hasSelectModifier($modifier) * * @param boolean $b True if case should be ignored. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setIgnoreCase($b) { @@ -1203,7 +1202,7 @@ public function isIgnoreCase() * * @param boolean $b Set to TRUE if you expect the query to select just one record. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setSingleRecord($b) { @@ -1227,7 +1226,7 @@ public function isSingleRecord() * * @param int $limit An int with the value for limit. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setLimit($limit) { @@ -1253,7 +1252,7 @@ public function getLimit() * @param int $offset An int with the value for offset. (Note this values is * cast to a 32bit integer and may result in truncation) * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setOffset($offset) { @@ -1277,7 +1276,7 @@ public function getOffset() * * @param string $name Name of the select column. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function addSelectColumn($name) { @@ -1291,7 +1290,7 @@ public function addSelectColumn($name) * * @param string $comment The comment to add to the query, without comment sign * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function setComment($comment = null) { @@ -1337,7 +1336,7 @@ public function getSelectColumns() /** * Clears current select columns. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function clearSelectColumns() { @@ -1361,7 +1360,7 @@ public function getSelectModifiers() * * @param string $groupBy The name of the column to group by. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function addGroupByColumn($groupBy) { @@ -1375,7 +1374,7 @@ public function addGroupByColumn($groupBy) * * @param string $name The name of the column to order by. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function addAscendingOrderByColumn($name) { @@ -1389,7 +1388,7 @@ public function addAscendingOrderByColumn($name) * * @param string $name The name of the column to order by. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function addDescendingOrderByColumn($name) { @@ -1411,7 +1410,7 @@ public function getOrderByColumns() /** * Clear the order-by columns. * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function clearOrderByColumns() { @@ -1423,7 +1422,7 @@ public function clearOrderByColumns() /** * Clear the group-by columns. * - * @return Criteria + * @return static */ public function clearGroupByColumns() { @@ -1586,7 +1585,7 @@ public function equals($crit) * Defaults to Criteria::LOGICAL_AND, also accepts Criteria::LOGICAL_OR * This parameter is deprecated, use _or() instead * - * @return Criteria The current criteria object + * @return static The current criteria object * * @throws PropelException */ @@ -1683,7 +1682,7 @@ public function mergeWith(Criteria $criteria, $operator = null) * @param mixed $value The value to bind in the condition * @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant * - * @return Criteria Modified Criteria object (for fluent API) + * @return static Modified Criteria object (for fluent API) */ public function addHaving($p1, $value = null, $comparison = null) { @@ -1748,7 +1747,7 @@ protected function getCriterionForCondition($p1, $value = null, $comparison = nu * @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant * @param bool $preferColumnCondition * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addAnd($p1, $value = null, $comparison = null, $preferColumnCondition = true) { @@ -1784,7 +1783,7 @@ public function addAnd($p1, $value = null, $comparison = null, $preferColumnCond * @param mixed $comparison A Criteria class constant, or a PDO::PARAM_ class constant * @param bool $preferColumnCondition * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addOr($p1, $value = null, $comparison = null, $preferColumnCondition = true) { @@ -1823,7 +1822,7 @@ public function addOr($p1, $value = null, $comparison = null, $preferColumnCondi * (necessary for Propel 1.4 compatibility). * If false, the condition is combined with the last existing condition. * - * @return Criteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addUsingOperator($p1, $value = null, $operator = null, $preferColumnCondition = true) { @@ -1839,7 +1838,7 @@ public function addUsingOperator($p1, $value = null, $operator = null, $preferCo // Fluid operators /** - * @return Criteria + * @return static */ public function _or() { @@ -1849,7 +1848,7 @@ public function _or() } /** - * @return Criteria + * @return static */ public function _and() { @@ -1916,7 +1915,7 @@ public function _else() * Returns the current object * Allows for conditional statements in a fluid interface. * - * @return Criteria + * @return static * * @throws PropelException */ diff --git a/runtime/lib/query/ModelCriteria.php b/runtime/lib/query/ModelCriteria.php index 48867c928..3d8743e7f 100644 --- a/runtime/lib/query/ModelCriteria.php +++ b/runtime/lib/query/ModelCriteria.php @@ -17,17 +17,19 @@ * * magic methods: * - * @method ModelCriteria leftJoin($relation) Adds a LEFT JOIN clause to the query - * @method ModelCriteria rightJoin($relation) Adds a RIGHT JOIN clause to the query - * @method ModelCriteria innerJoin($relation) Adds a INNER JOIN clause to the query - * @method ModelCriteria getSelectQuery($alias) Get the Criteria for a specific subQuery - * @method ModelCriteria _or() + * @method static leftJoin($relation) Adds a LEFT JOIN clause to the query + * @method static rightJoin($relation) Adds a RIGHT JOIN clause to the query + * @method static innerJoin($relation) Adds a INNER JOIN clause to the query + * @method static getSelectQuery($alias) Get the Criteria for a specific subQuery + * @method static _or() * * @property ModelJoin[] $joins * * @author François Zaninotto * @version $Revision$ * @package propel.runtime.query + * + * @psalm-consistent-constructor */ class ModelCriteria extends Criteria { @@ -52,6 +54,8 @@ class ModelCriteria extends Criteria * @var DatabaseMap */ protected $tableMap; + + /** @var ModelCriteria|null */ protected $primaryCriteria = null; protected $formatter = null; protected $defaultFormatterClass = ModelCriteria::FORMAT_OBJECT; @@ -98,7 +102,7 @@ public function getModelName() * @param string $modelAlias The model alias * @param boolean $useAliasInSQL Whether to use the alias in the SQL code (false by default) * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function setModelAlias($modelAlias, $useAliasInSQL = false) { @@ -161,7 +165,7 @@ public function getTableMap() * * @param string|PropelFormatter $formatter a formatter class name, or a formatter instance * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -210,7 +214,7 @@ public function getFormatter() * @param mixed $value A value for the condition * @param mixed $bindingType A value for the condition * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function condition($conditionName, $clause, $value = null, $bindingType = null) { @@ -233,7 +237,7 @@ public function condition($conditionName, $clause, $value = null, $bindingType = * @param mixed $value A value for the condition * @param string $comparison What to use for the column comparison, defaults to Criteria::EQUAL * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function filterBy($column, $value, $comparison = Criteria::EQUAL) { @@ -255,7 +259,7 @@ public function filterBy($column, $value, $comparison = Criteria::EQUAL) * * @param mixed $conditions An array of conditions, using column phpNames as key * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function filterByArray($conditions) { @@ -285,7 +289,7 @@ public function filterByArray($conditions) * @param mixed $value A value for the condition * @param string $bindingType * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function where($clause, $value = null, $bindingType = null) { @@ -320,7 +324,7 @@ public function where($clause, $value = null, $bindingType = null) * @param mixed $value A value for the condition * @param string $bindingType * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function orWhere($clause, $value = null, $bindingType = null) { @@ -348,7 +352,7 @@ public function orWhere($clause, $value = null, $bindingType = null) * @param mixed $value A value for the condition * @param string $bindingType * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function having($clause, $value = null, $bindingType = null) { @@ -377,7 +381,7 @@ public function having($clause, $value = null, $bindingType = null) * @param string $columnName The column to order by * @param string $order The sorting order. Criteria::ASC by default, also accepts Criteria::DESC * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -409,7 +413,7 @@ public function orderBy($columnName, $order = Criteria::ASC) * * @param string $columnName The column to group by * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function groupBy($columnName) { @@ -430,7 +434,7 @@ public function groupBy($columnName) * * @param string $class The class name or alias * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -460,7 +464,7 @@ public function groupByClass($class) * Adds a DISTINCT clause to the query * Alias for Criteria::setDistinct() * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function distinct() { @@ -475,7 +479,7 @@ public function distinct() * * @param int $limit Maximum number of results to return by the query * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function limit($limit) { @@ -490,7 +494,7 @@ public function limit($limit) * * @param int $offset Offset of the first result to return * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function offset($offset) { @@ -519,7 +523,7 @@ public function offset($offset) * * @param mixed $columnArray A list of column names (e.g. array('Title', 'Category.Name', 'c.Content')) or a single column name (e.g. 'Name') * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -652,7 +656,7 @@ public function getJoin($name) * @param string $relation Relation to use for the join * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -721,7 +725,7 @@ public function join($relation, $joinType = Criteria::INNER_JOIN) * @param string $operator The operator to use to add the condition. Defaults to 'AND' * @param string $bindingType * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -756,7 +760,7 @@ public function addJoinCondition($name, $clause, $value = null, $operator = null * @param string $name The relation name or alias on which the join was created * @param mixed $condition A Criterion object, or a condition name * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -784,7 +788,7 @@ public function setJoinCondition($name, $condition) * @param Join $join A join object * @param string $name * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function addJoinObject(Join $join, $name = null) { @@ -822,7 +826,7 @@ public function addJoinObject(Join $join, $name = null) * @param string $relation Relation to use for the join * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join' * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function joinWith($relation, $joinType = Criteria::INNER_JOIN) { @@ -848,7 +852,7 @@ public function joinWith($relation, $joinType = Criteria::INNER_JOIN) * * @param string $relation Relation to use for the join * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface * * @throws PropelException */ @@ -898,7 +902,7 @@ public function getWith() * * @param array $with * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function setWith($with) { @@ -922,7 +926,7 @@ public function isWithOneToMany() * If no alias is provided, the clause is used as a column alias * This alias is used for retrieving the column via BaseObject::getVirtualColumn($alias) * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function withColumn($clause, $name = null) { @@ -945,10 +949,12 @@ public function withColumn($clause, $name = null) * * @see ModelCriteria::endUse() * + * @template T as ModelCriteria + * * @param string $relationName Relation name or alias - * @param string $secondaryCriteriaClass Classname for the ModelCriteria to be used + * @param class-string|null $secondaryCriteriaClass Classname for the ModelCriteria to be used * - * @return ModelCriteria The secondary criteria object + * @return T The secondary criteria object * * @throws PropelException */ @@ -959,6 +965,7 @@ public function useQuery($relationName, $secondaryCriteriaClass = null) } $className = $this->joins[$relationName]->getTableMap()->getPhpName(); if (null === $secondaryCriteriaClass) { + /** @psalm-var T $secondaryCriteria */ $secondaryCriteria = PropelQuery::from($className); } else { $secondaryCriteria = new $secondaryCriteriaClass(); @@ -983,7 +990,11 @@ public function endUse() if (isset($this->aliases[$this->modelAlias])) { $this->removeAlias($this->modelAlias); } - $primaryCriteria = $this->getPrimaryCriteria(); + + if (null === $primaryCriteria = $this->getPrimaryCriteria()) { + throw new LogicException('Primary criteria was not set'); + } + $primaryCriteria->mergeWith($this); return $primaryCriteria; @@ -999,7 +1010,7 @@ public function endUse() * @param string $operator The logical operator used to combine conditions * Defaults to Criteria::LOGICAL_AND, also accepts Criteria::LOGICAL_OR * - * @return ModelCriteria The primary criteria object + * @return static The primary criteria object */ public function mergeWith(Criteria $criteria, $operator = null) { @@ -1017,9 +1028,9 @@ public function mergeWith(Criteria $criteria, $operator = null) * Clear the conditions to allow the reuse of the query object. * The ModelCriteria's Model and alias 'all the properties set by construct) will remain. * - * @return ModelCriteria The primary criteria object + * @return static The primary criteria object */ - public function clear() + public function clear(): static { parent::clear(); @@ -1055,7 +1066,7 @@ public function setPrimaryCriteria(ModelCriteria $criteria, Join $previousJoin) /** * Gets the primary criteria for this secondary Criteria * - * @return ModelCriteria The primary criteria + * @return ModelCriteria|null The primary criteria */ public function getPrimaryCriteria() { @@ -1071,7 +1082,7 @@ public function getPrimaryCriteria() * @param string $alias alias for the subQuery * @param boolean $addAliasAndSelectColumns Set to false if you want to manually add the aliased select columns * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function addSelectQuery(Criteria $subQueryCriteria, $alias = null, $addAliasAndSelectColumns = true) { @@ -1097,7 +1108,7 @@ public function addSelectQuery(Criteria $subQueryCriteria, $alias = null, $addAl /** * Adds the select columns for a the current table * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function addSelfSelectColumns() { @@ -1111,7 +1122,7 @@ public function addSelfSelectColumns() * * @param string $relation The relation name or alias, as defined in join() * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function addRelationSelectColumns($relation) { @@ -1172,7 +1183,7 @@ public static function getRelationName($relation) * * @param boolean $isKeepQuery * - * @return ModelCriteria The current object, for fluid interface + * @return static The current object, for fluid interface */ public function keepQuery($isKeepQuery = true) { @@ -2176,7 +2187,7 @@ public function getAliasedColName($colName) * @param mixed $value * @param string $operator A String, like Criteria::EQUAL. * - * @return ModelCriteria A modified Criteria object. + * @return static A modified Criteria object. */ public function addUsingAlias($column, $value = null, $operator = null) {