From ec57156d5ac1fd72e7c498e54d577ff7a61abc41 Mon Sep 17 00:00:00 2001 From: Marcin Gil Date: Fri, 18 Apr 2025 17:24:34 +0200 Subject: [PATCH] PHP 8.4: Implicitly nullable parameter declarations deprecated https://php.watch/versions/8.4/implicitly-marking-parameter-type-nullable-deprecated Fixes error: Implicitly marking parameter ? as nullable is deprecated, the explicit nullable type must be used instead Fix using Zf1s\Compat\Types --- composer.json | 9 ++- lib/Doctrine/Cli.php | 10 ++- lib/Doctrine/Collection.php | 115 +++++++++++++++------------- lib/Doctrine/Connection/Mssql.php | 73 ++++++++++-------- lib/Doctrine/Locator.php | 25 +++--- lib/Doctrine/Query.php | 9 ++- lib/Doctrine/Query/Abstract.php | 68 ++++++++-------- lib/Doctrine/Query/Part.php | 9 ++- lib/Doctrine/RawSql.php | 32 ++++---- lib/Doctrine/Record.php | 111 +++++++++++++++------------ lib/Doctrine/Table.php | 21 +++-- lib/Doctrine/Tree/Interface.php | 4 +- lib/Doctrine/Tree/NestedSet.php | 21 +++-- tests/DoctrineTest/GroupTest.php | 7 +- tests/DoctrineTest/UnitTestCase.php | 19 +++-- tests/Ticket/1830TestCase.php | 15 ++-- tests/Ticket/1876bTestCase.php | 46 ++++++----- tests/Ticket/1935TestCase.php | 6 +- 18 files changed, 349 insertions(+), 251 deletions(-) diff --git a/composer.json b/composer.json index feba3845a..5f48a0127 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,19 @@ {"name": "Konsta Vesterinen", "email": "kvesteri@cc.hut.fi"}, {"name": "Jonathan Wage", "email": "jonwage@gmail.com"} ], + "repositories": [ + { + "type": "git", + "url": "git@github.com:zf1s/compat.git" + } + ], "replace": { "doctrine/doctrine1": "*" }, "require": { "php": ">=5.3.3", - "ext-pdo": "*" + "ext-pdo": "*", + "zf1s/compat": "^1.0" }, "autoload": { "psr-0": { diff --git a/lib/Doctrine/Cli.php b/lib/Doctrine/Cli.php index c4da33f15..b17141c1c 100644 --- a/lib/Doctrine/Cli.php +++ b/lib/Doctrine/Cli.php @@ -1,4 +1,7 @@ setConfig($config); $this->setFormatter($formatter ? $formatter : new Doctrine_Cli_AnsiColorFormatter()); $this->includeAndRegisterTaskClasses(); diff --git a/lib/Doctrine/Collection.php b/lib/Doctrine/Collection.php index 4528e3b82..72fad4c89 100644 --- a/lib/Doctrine/Collection.php +++ b/lib/Doctrine/Collection.php @@ -1,4 +1,7 @@ data = $data; } @@ -188,7 +191,7 @@ public function unserialize($serialized) { $this->__unserialize(unserialize($serialized)); } - + /** * As of PHP 8.1.0, a class which implements Serializable without also implementing __serialize() and __unserialize() will generate a deprecation warning. * @see https://php.watch/versions/8.1/serializable-deprecated @@ -225,7 +228,7 @@ public function __unserialize(array $array) public function setKeyColumn($column) { $this->keyColumn = $column; - + return $this; } @@ -299,7 +302,7 @@ public function setReference(Doctrine_Record $record, Doctrine_Relation $relatio $this->reference = $record; $this->relation = $relation; - if ($relation instanceof Doctrine_Relation_ForeignKey || + if ($relation instanceof Doctrine_Relation_ForeignKey || $relation instanceof Doctrine_Relation_LocalKey) { $this->referenceField = $relation->getForeignFieldName(); @@ -355,7 +358,7 @@ public function contains($key) /** * Search a Doctrine_Record instance * - * @param string $Doctrine_Record + * @param string $Doctrine_Record * @return void */ public function search(Doctrine_Record $record) @@ -396,7 +399,7 @@ public function get($key) if ($key === null) { $this->data[] = $record; } else { - $this->data[$key] = $record; + $this->data[$key] = $record; } if (isset($this->keyColumn)) { @@ -522,10 +525,10 @@ public function add($record, $key = null) return true; } - + /** * Merges collection into $this and returns merged collection - * + * * @param Doctrine_Collection $coll * @return Doctrine_Collection */ @@ -533,15 +536,15 @@ public function merge(Doctrine_Collection $coll) { $localBase = $this->getTable()->getComponentName(); $otherBase = $coll->getTable()->getComponentName(); - + if ($otherBase != $localBase && !is_subclass_of($otherBase, $localBase) ) { throw new Doctrine_Collection_Exception("Can't merge collections with incompatible record types"); } - + foreach ($coll->getData() as $record) { $this->add($record); } - + return $this; } @@ -685,7 +688,7 @@ public function getNormalIterator() public function takeSnapshot() { $this->_snapshot = $this->data; - + return $this; } @@ -710,7 +713,7 @@ public function getSnapshot() * * @return Doctrine_Collection */ - public function processDiff() + public function processDiff() { foreach (array_udiff($this->_snapshot, $this->data, array($this, "compareRecords")) as $record) { $record->delete(); @@ -728,20 +731,20 @@ public function toArray($deep = true, $prefixKey = false) { $data = array(); foreach ($this as $key => $record) { - + $key = $prefixKey ? get_class($record) . '_' .$key:$key; - + $data[$key] = $record->toArray($deep, $prefixKey); } - + return $data; } /** * Build an array made up of the values from the 2 specified columns * - * @param string $key - * @param string $value + * @param string $key + * @param string $value * @return array $result */ public function toKeyValueArray($key, $value) @@ -804,7 +807,7 @@ public function toHierarchy() /** * Populate a Doctrine_Collection from an array of data * - * @param string $array + * @param string $array * @return void */ public function fromArray($array, $deep = true) @@ -852,8 +855,8 @@ public function synchronizeFromArray(array $array) /** * Export a Doctrine_Collection to one of the supported Doctrine_Parser formats * - * @param string $type - * @param string $deep + * @param string $type + * @param string $deep * @return void */ public function exportTo($type, $deep = true) @@ -868,8 +871,8 @@ public function exportTo($type, $deep = true) /** * Import data to a Doctrine_Collection from one of the supported Doctrine_Parser formats * - * @param string $type - * @param string $data + * @param string $type + * @param string $data * @return void */ public function importFrom($type, $data) @@ -906,8 +909,8 @@ public function getInsertDiff() * * @throws Doctrine_Collection_Exception * - * @param Doctrine_Record $a - * @param Doctrine_Record $b + * @param Doctrine_Record $a + * @param Doctrine_Record $b * @return integer */ protected function compareRecords($a, $b) @@ -924,23 +927,25 @@ protected function compareRecords($a, $b) if ($a->getOid() == $b->getOid()) { return 0; } - + return ($a->getOid() > $b->getOid()) ? 1 : -1; } /** - * Saves all records of this collection and processes the + * Saves all records of this collection and processes the * difference of the last snapshot and the current data * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @return Doctrine_Collection */ - public function save(Doctrine_Connection $conn = null, $processDiff = true) + public function save($conn = null, $processDiff = true) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + if ($conn == null) { $conn = $this->_table->getConnection(); } - + try { $conn->beginInternalTransaction(); @@ -964,14 +969,16 @@ public function save(Doctrine_Connection $conn = null, $processDiff = true) } /** - * Replaces all records of this collection and processes the + * Replaces all records of this collection and processes the * difference of the last snapshot and the current data * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @return Doctrine_Collection */ - public function replace(Doctrine_Connection $conn = null, $processDiff = true) + public function replace($conn = null, $processDiff = true) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + if ($conn == null) { $conn = $this->_table->getConnection(); } @@ -1003,12 +1010,14 @@ public function replace(Doctrine_Connection $conn = null, $processDiff = true) * * @return Doctrine_Collection */ - public function delete(Doctrine_Connection $conn = null, $clearColl = true) + public function delete($conn = null, $clearColl = true) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + if ($conn == null) { $conn = $this->_table->getConnection(); } - + try { $conn->beginInternalTransaction(); $conn->transaction->addCollection($this); @@ -1022,14 +1031,14 @@ public function delete(Doctrine_Connection $conn = null, $clearColl = true) $conn->rollback(); throw $e; } - + if ($clearColl) { $this->clear(); } - + return $this; } - + /** * Clears the collection. * @@ -1084,7 +1093,7 @@ public function __toString() { return Doctrine_Lib::getCollectionAsString($this); } - + /** * Returns the relation object * @@ -1095,22 +1104,22 @@ public function getRelation() return $this->relation; } - /** - * checks if one of the containing records is modified - * returns true if modified, false otherwise - * - * @return boolean - */ - final public function isModified() { - $dirty = (count($this->getInsertDiff()) > 0 || count($this->getDeleteDiff()) > 0); - if ( ! $dirty) { - foreach($this as $record) { + /** + * checks if one of the containing records is modified + * returns true if modified, false otherwise + * + * @return boolean + */ + final public function isModified() { + $dirty = (count($this->getInsertDiff()) > 0 || count($this->getDeleteDiff()) > 0); + if ( ! $dirty) { + foreach($this as $record) { if ($dirty = $record->isModified()) { break; - } - } - } - return $dirty; + } + } + } + return $dirty; } // [OV2] added diff --git a/lib/Doctrine/Connection/Mssql.php b/lib/Doctrine/Connection/Mssql.php index 9f36b8b12..71cbb1736 100644 --- a/lib/Doctrine/Connection/Mssql.php +++ b/lib/Doctrine/Connection/Mssql.php @@ -1,4 +1,7 @@ getAttribute(Doctrine_Core::ATTR_QUOTE_IDENTIFIER)) { return $identifier; } - - if (strpos($identifier, '.') !== false) { - $parts = explode('.', $identifier); - $quotedParts = array(); - foreach ($parts as $p) { - $quotedParts[] = $this->quoteIdentifier($p); + + if (strpos($identifier, '.') !== false) { + $parts = explode('.', $identifier); + $quotedParts = array(); + foreach ($parts as $p) { + $quotedParts[] = $this->quoteIdentifier($p); } - - return implode('.', $quotedParts); + + return implode('.', $quotedParts); } - + return '[' . str_replace(']', ']]', $identifier) . ']'; } @@ -108,21 +111,21 @@ public function quoteIdentifier($identifier, $checkOption = false) * * Copyright (c) 2005-2008, Zend Technologies USA, Inc. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * + * * * Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. - * + * * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. - * + * * * Neither the name of Zend Technologies USA, Inc. nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE @@ -140,10 +143,12 @@ public function quoteIdentifier($identifier, $checkOption = false) * @link http://lists.bestpractical.com/pipermail/rt-devel/2005-June/007339.html * @return string */ - public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false, $isSubQuery = false, Doctrine_Query $queryOrigin = null) + public function modifyLimitQuery($query, $limit = false, $offset = false, $isManip = false, $isSubQuery = false, $queryOrigin = null) { + Types::isNullable('queryOrigin', $queryOrigin, 'Doctrine_Query'); + if ($limit === false || !($limit > 0)) { - return $query; + return $query; } $orderby = stristr($query, 'ORDER BY'); @@ -151,7 +156,7 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan if ($offset !== false && $orderby === false) { throw new Doctrine_Connection_Exception("OFFSET cannot be used in MSSQL without ORDER BY due to emulation reasons."); } - + $count = intval($limit); $offset = intval($offset); @@ -206,14 +211,14 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan } if ($orderby !== false) { - $query .= ' ORDER BY '; + $query .= ' ORDER BY '; - for ($i = 0, $l = count($orders); $i < $l; $i++) { - if ($i > 0) { // not first order clause - $query .= ', '; - } + for ($i = 0, $l = count($orders); $i < $l; $i++) { + if ($i > 0) { // not first order clause + $query .= ', '; + } - $query .= $this->modifyOrderByColumn($tables[$i], $columns[$i], $this->quoteIdentifier('inner_tbl') . '.' . $this->quoteIdentifier($aliases[$i])) . ' '; + $query .= $this->modifyOrderByColumn($tables[$i], $columns[$i], $this->quoteIdentifier('inner_tbl') . '.' . $this->quoteIdentifier($aliases[$i])) . ' '; $query .= (stripos($sorts[$i], 'asc') !== false) ? 'DESC' : 'ASC'; } } @@ -238,8 +243,8 @@ public function modifyLimitQuery($query, $limit = false, $offset = false, $isMan } /** - * Parse an OrderBy-Statement into chunks - * + * Parse an OrderBy-Statement into chunks + * * @param string $orderby */ private function parseOrderBy($orderby) @@ -250,16 +255,16 @@ private function parseOrderBy($orderby) $parsed = str_ireplace('ORDER BY', '', $orderby); preg_match_all('/(\w+\(.+?\)\s+(ASC|DESC)),?/', $orderby, $matches); - + $matchesWithExpressions = $matches[1]; foreach ($matchesWithExpressions as $match) { $chunks[] = $match; $parsed = str_replace($match, '##' . (count($chunks) - 1) . '##', $parsed); } - + $tokens = preg_split('/,/', $parsed); - + for ($i = 0, $iMax = count($tokens); $i < $iMax; $i++) { $tokens[$i] = trim(preg_replace_callback( @@ -273,15 +278,15 @@ function ($m) use($chunks) { return $tokens; } - + /** * Order and Group By are not possible on columns from type text. - * This method fix this issue by wrap the given term (column) into a CAST directive. - * + * This method fix this issue by wrap the given term (column) into a CAST directive. + * * @see DC-828 * @param Doctrine_Table $table * @param string $field - * @param string $term The term which will changed if it's necessary, depending to the field type. + * @param string $term The term which will changed if it's necessary, depending to the field type. * @return string */ public function modifyOrderByColumn(Doctrine_Table $table, $field, $term) @@ -291,7 +296,7 @@ public function modifyOrderByColumn(Doctrine_Table $table, $field, $term) if ($def['type'] == 'string' && $def['length'] === NULL) { $term = 'CAST(' . $term . ' AS varchar(8000))'; } - + return $term; } @@ -305,7 +310,7 @@ public function modifyLimitSubquery(Doctrine_Table $rootTable, $query, $limit = { return $this->modifyLimitQuery($query, $limit, $offset, $isManip, true); } - + /** * return version information about the server * diff --git a/lib/Doctrine/Locator.php b/lib/Doctrine/Locator.php index 723daa081..a8afae639 100644 --- a/lib/Doctrine/Locator.php +++ b/lib/Doctrine/Locator.php @@ -1,4 +1,7 @@ $resource) { if ($resource instanceof Doctrine_Locator_Injectable) { @@ -69,7 +74,7 @@ public function __construct(array $defaults = null) self::$_instances[] = $this; } - /** + /** * instance * * @return Sensei_Locator @@ -87,7 +92,7 @@ public static function instance() * * @param string $prefix */ - public function setClassPrefix($prefix) + public function setClassPrefix($prefix) { $this->_classPrefix = $prefix; } @@ -124,7 +129,7 @@ public function contains($name) public function bind($name, $value) { $this->_resources[$name] = $value; - + return $this; } @@ -149,9 +154,9 @@ public function locate($name) $name = array_map('strtolower', $name); $name = array_map('ucfirst', $name); $name = implode('_', $name); - + $className = $this->_classPrefix . $name; - + if ( ! class_exists($className)) { throw new Doctrine_Locator_Exception("Couldn't locate resource " . $className); } @@ -184,10 +189,10 @@ public function count() /** * getIterator - * returns an ArrayIterator that iterates through all + * returns an ArrayIterator that iterates through all * bound resources * - * @return ArrayIterator an iterator for iterating through + * @return ArrayIterator an iterator for iterating through * all bound resources */ public function getIterator() diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index d39158911..f5b8c63e6 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -1,4 +1,7 @@ getCurrentConnection(); } else { @@ -424,7 +430,7 @@ public function getDqlWithParams() { $dql = $this->getDql(); $params = $this->getFlattenedParams(); - + // [OV13] $dql = $this->_adjustWhereInSql($dql, $params); @@ -570,7 +576,7 @@ public function getParams() public function getFlattenedParams($params = array()) { return array_merge( - (array) $params, (array) $this->_params['exec'], + (array) $params, (array) $this->_params['exec'], $this->_params['join'], $this->_params['set'], $this->_params['where'], $this->_params['having'] ); @@ -595,7 +601,7 @@ public function setParams(array $params = array()) { $this->_params = $params; } - + /** * getCountQueryParams * Retrieves the parameters for count query @@ -627,7 +633,7 @@ public function getCountQueryParams($params = array()) * @param int $index * @return array */ - protected function _adjustProcessedParam(array $params = null, $index) + protected function _adjustProcessedParam($params, $index) { // Retrieve all params $params = null !== $params ? $params : $this->getInternalParams(); @@ -655,13 +661,13 @@ public function fixArrayParameterValues($params = array()) $c = count($param); array_splice($params, $i, 1, $param); - + $i += $c; } else { $i++; } } - + $this->_execParams = $params; } @@ -728,17 +734,17 @@ public function getInheritanceCondition($componentAlias) $tableAlias .= '.'; } - // Fix for 2015: loop through whole inheritanceMap to add all - // keyFields for inheritance (and not only the first) - $retVal = ""; - $count = 0; - - foreach ($map as $field => $value) { + // Fix for 2015: loop through whole inheritanceMap to add all + // keyFields for inheritance (and not only the first) + $retVal = ""; + $count = 0; + + foreach ($map as $field => $value) { if ($count++ > 0) { $retVal .= ' AND '; } - $identifier = $this->_conn->quoteIdentifier($tableAlias . $field); + $identifier = $this->_conn->quoteIdentifier($tableAlias . $field); $retVal .= $identifier . ' = ' . $this->_conn->quote($value); } @@ -877,7 +883,7 @@ public function getRootAlias() if ( ! $this->_queryComponents) { $this->getSqlQuery(array(), false); } - + return $this->_rootAlias; } @@ -1052,13 +1058,13 @@ protected function _execute($params) if ($cached) { // Rebuild query from cache $query = $this->_constructQueryFromCache($cached); - + // Assign building/execution specific params $this->_params['exec'] = $params; - + // Initialize prepared parameters array $this->_execParams = $this->getFlattenedParams(); - + // Fix possible array parameter values in SQL params $this->fixArrayParameterValues($this->getInternalParams()); } else { @@ -1081,7 +1087,7 @@ protected function _execute($params) } else { $query = $this->_view->getSelectSql(); } - + // Get prepared SQL params for execution $params = $this->getInternalParams(); @@ -1166,7 +1172,7 @@ public function execute($params = array(), $hydrationMode = null) $this->_hydrator->setQueryComponents($this->_queryComponents); if ($this->_type == self::SELECT && $hydrationMode == Doctrine_Core::HYDRATE_ON_DEMAND) { $hydrationDriver = $this->_hydrator->getHydratorDriver($hydrationMode, $this->_tableAliasMap); - $result = new Doctrine_Collection_OnDemand($stmt, $hydrationDriver, $this->_tableAliasMap); + $result = new Doctrine_Collection_OnDemand($stmt, $hydrationDriver, $this->_tableAliasMap); } else { $result = $this->_hydrator->hydrateResultSet($stmt, $this->_tableAliasMap); } @@ -1183,7 +1189,7 @@ public function execute($params = array(), $hydrationMode = null) * Blank template method free(). Override to be used to free query object memory */ public function free() - { + { } /** @@ -1245,7 +1251,7 @@ protected function _preQuery($params = array()) // Trigger preDql*() callback event $params = array('component' => $component, 'alias' => $alias); $event = new Doctrine_Event($record, $callback['const'], $this, $params); - + $record->{$callback['callback']}($event); $table->getRecordListener()->{$callback['callback']}($event); } @@ -1318,9 +1324,9 @@ protected function _constructQueryFromCache($cached) foreach ($cachedComponents as $alias => $components) { $e = explode('.', $components['name']); if (count($e) === 1) { - $manager = Doctrine_Manager::getInstance(); - if ( ! $this->_passedConn && $manager->hasConnectionForComponent($e[0])) { - $this->_conn = $manager->getConnectionForComponent($e[0]); + $manager = Doctrine_Manager::getInstance(); + if ( ! $this->_passedConn && $manager->hasConnectionForComponent($e[0])) { + $this->_conn = $manager->getConnectionForComponent($e[0]); } $queryComponents[$alias]['table'] = $this->_conn->getTable($e[0]); } else { @@ -1586,7 +1592,7 @@ protected function _processWhereIn($expr, $params = array(), $not = false) // [OV13] just store the params array $this->_params['where'][] = $params; } - + return $expr . ($not === true ? ' NOT' : '') . ' IN ' . ($mixed ? '(' . implode(', ', $a) . ')' : '?'); } @@ -1707,7 +1713,7 @@ public function addGroupBy($groupby) /** * Adds conditions to the HAVING part of the query. * - * This methods add HAVING clauses. These clauses are used to narrow the + * This methods add HAVING clauses. These clauses are used to narrow the * results by operating on aggregated values. * * $q->having('num_phonenumbers > ?', 1); diff --git a/lib/Doctrine/Query/Part.php b/lib/Doctrine/Query/Part.php index 629ed2ad4..d1bbeca4b 100644 --- a/lib/Doctrine/Query/Part.php +++ b/lib/Doctrine/Query/Part.php @@ -1,4 +1,7 @@ query = $query; if ( ! $tokenizer) { diff --git a/lib/Doctrine/RawSql.php b/lib/Doctrine/RawSql.php index 18658f10b..89d392c00 100644 --- a/lib/Doctrine/RawSql.php +++ b/lib/Doctrine/RawSql.php @@ -1,4 +1,7 @@ _sqlParts[$queryPartName])) { $this->_sqlParts[$queryPartName] = array(); } - + if ( ! $append) { $this->_sqlParts[$queryPartName] = array($queryPart); } else { @@ -95,7 +101,7 @@ public function parseDqlQueryPart($queryPartName, $queryPart, $append = false) } return $this; } - + /** * Adds a DQL query part. Overrides Doctrine_Query_Abstract::_addDqlQueryPart(). * This implementation for RawSql parses the new parts right away, generating the SQL. @@ -104,7 +110,7 @@ protected function _addDqlQueryPart($queryPartName, $queryPart, $append = false) { return $this->parseDqlQueryPart($queryPartName, $queryPart, $append); } - + /** * Add select parts to fields. * @@ -116,7 +122,7 @@ private function _parseSelectFields($queryPart) $this->fields = $m[1]; $this->_sqlParts['select'] = array(); } - + /** * parseDqlQuery * parses an sql query and adds the parts to internal array. @@ -168,7 +174,7 @@ public function parseDqlQuery($query) $parts[$type][0] = $part; } else { // why does this add to index 0 and not append to the - // array. If it had done that one could have used + // array. If it had done that one could have used // parseQueryPart. $parts[$type][0] .= ' '.$part; } @@ -188,7 +194,7 @@ public function parseDqlQuery($query) * @return string the built sql query */ public function getSqlQuery($params = array()) - { + { // Assign building/execution specific params $this->_params['exec'] = $params; @@ -199,7 +205,7 @@ public function getSqlQuery($params = array()) $this->fixArrayParameterValues($this->_execParams); $select = array(); - + $formatter = $this->getConnection()->formatter; foreach ($this->fields as $field) { @@ -217,7 +223,7 @@ public function getSqlQuery($params = array()) } $componentAlias = $this->getComponentAlias($e[0]); - + if ($e[1] == '*') { foreach ($this->_queryComponents[$componentAlias]['table']->getColumnNames() as $name) { $field = $formatter->quoteIdentifier($e[0]) . '.' . $formatter->quoteIdentifier($name); @@ -254,7 +260,7 @@ public function getSqlQuery($params = array()) // first add the fields of the root component reset($this->_queryComponents); $componentAlias = key($this->_queryComponents); - + $this->_rootAlias = $componentAlias; $q .= implode(', ', $select[$componentAlias]); @@ -422,7 +428,7 @@ public function addComponent($tableAlias, $path) if ( ! isset($table)) { $conn = Doctrine_Manager::getInstance() ->getConnectionForComponent($component); - + $table = $conn->getTable($component); $this->_queryComponents[$componentAlias] = array('table' => $table); } else { diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index fa5498781..0f225f4d6 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -1,4 +1,7 @@ keys to be executed after save * @@ -275,7 +278,7 @@ public function __construct($table = null, $isNewEntry = false) } $repository = $this->_table->getRepository(); - + // Fix for #1682 and #1841. // Doctrine_Table does not have the repository yet during dummy record creation. if ($repository) { @@ -415,9 +418,9 @@ public function isValid($deep = false, $hooks = true) $event = new Doctrine_Event($this, Doctrine_Event::RECORD_VALIDATE); $this->preValidate($event); $this->getTable()->getRecordListener()->preValidate($event); - + if ( ! $event->skipOperation) { - + $validator = new Doctrine_Validator(); $validator->validateRecord($this); $this->validate(); @@ -578,7 +581,7 @@ public function postInsert($event) /** * Empty template method to provide concrete Record classes with the possibility - * to hook into the validation procedure. Useful for cleaning up data before + * to hook into the validation procedure. Useful for cleaning up data before * validating it. */ public function preValidate($event) @@ -612,14 +615,14 @@ public function preDqlDelete($event) { } /** - * Empty template method to provide Record classes with the ability to alter hydration + * Empty template method to provide Record classes with the ability to alter hydration * before it runs */ public function preHydrate($event) { } /** - * Empty template method to provide Record classes with the ability to alter hydration + * Empty template method to provide Record classes with the ability to alter hydration * after it runs */ public function postHydrate($event) @@ -658,7 +661,7 @@ public function getErrorStack() if ( ! $this->_errorStack) { $this->_errorStack = new Doctrine_Validator_ErrorStack(get_class($this)); } - + return $this->_errorStack; } @@ -937,7 +940,7 @@ public function __unserialize(array $array) $connection = $manager->getConnectionForComponent(get_class($this)); $this->_table = $connection->getTable(get_class($this)); - + $this->preUnserialize($event); $this->getTable()->getRecordListener()->preUnserialize($event); @@ -1000,7 +1003,7 @@ public function state($state = null) if ($state == null) { return $this->_state; } - + $err = false; if (is_integer($state)) { if ($state >= 1 && $state <= 7) { @@ -1151,7 +1154,7 @@ public function clearRelated($name = null) * in order to check. If the reference didn't already exist and it doesn't * exist in the database, the related reference will be cleared immediately. * - * @param string $name + * @param string $name * @return boolean Whether or not the related relationship exists */ public function relatedExists($name) @@ -1231,18 +1234,18 @@ public function load(array $data = array()) // only load the data from database if the Doctrine_Record is in proxy state if ($this->exists() && $this->isInProxyState()) { $id = $this->identifier(); - + if ( ! is_array($id)) { $id = array($id); } - + if (empty($id)) { return false; } $table = $this->getTable(); $data = empty($data) ? $table->find($id, Doctrine_Core::HYDRATE_ARRAY) : $data; - + if (is_array($data)) { foreach ($data as $field => $value) { if ($table->hasField($field) && ( ! array_key_exists($field, $this->_data) || $this->_data[$field] === self::$_null)) { @@ -1250,19 +1253,19 @@ public function load(array $data = array()) } } } - + if ($this->isModified()) { $this->_state = Doctrine_Record::STATE_DIRTY; } else if (!$this->isInProxyState()) { $this->_state = Doctrine_Record::STATE_CLEAN; } - + return true; } - + return false; } - + /** * indicates whether record has any not loaded fields * @@ -1286,8 +1289,8 @@ public function isInProxyState() * sets a fieldname to have a custom accessor or check if a field has a custom * accessor defined (when called without $accessor parameter). * - * @param string $fieldName - * @param string $accessor + * @param string $fieldName + * @param string $accessor * @return boolean */ public function hasAccessor($fieldName, $accessor = null) @@ -1303,7 +1306,7 @@ public function hasAccessor($fieldName, $accessor = null) /** * clears the accessor for a field name * - * @param string $fieldName + * @param string $fieldName * @return void */ public function clearAccessor($fieldName) @@ -1315,7 +1318,7 @@ public function clearAccessor($fieldName) /** * gets the custom accessor for a field name * - * @param string $fieldName + * @param string $fieldName * @return string $accessor */ public function getAccessor($fieldName) @@ -1341,8 +1344,8 @@ public function getAccessors() * sets a fieldname to have a custom mutator or check if a field has a custom * mutator defined (when called without the $mutator parameter) * - * @param string $fieldName - * @param string $mutator + * @param string $fieldName + * @param string $mutator * @return boolean */ public function hasMutator($fieldName, $mutator = null) @@ -1358,7 +1361,7 @@ public function hasMutator($fieldName, $mutator = null) /** * gets the custom mutator for a field name * - * @param string $fieldname + * @param string $fieldname * @return string */ public function getMutator($fieldName) @@ -1372,7 +1375,7 @@ public function getMutator($fieldName) /** * clears the custom mutator for a field name * - * @param string $fieldName + * @param string $fieldName * @return void */ public function clearMutator($fieldName) @@ -1418,7 +1421,7 @@ public function get($fieldName, $load = true) if ($this->_table->getAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE) || $this->hasAccessor($fieldName)) { $componentName = $this->_table->getComponentName(); - $accessor = $this->hasAccessor($fieldName) + $accessor = $this->hasAccessor($fieldName) ? $this->getAccessor($fieldName) : 'get' . Doctrine_Inflector::classify($fieldName); @@ -1449,10 +1452,10 @@ protected function _get($fieldName, $load = true) } else { $value = $this->_data[$fieldName]; } - + return $value; } - + try { if ( ! isset($this->_references[$fieldName])) { if ($load) { @@ -1557,10 +1560,10 @@ protected function _set($fieldName, $value, $load = true) } else { $old = $this->_data[$fieldName]; } - + if ($this->_isValueModified($type, $old, $value)) { if ($value === null) { - $value = $this->_table->getDefaultValueOf($fieldName); + $value = $this->_table->getDefaultValueOf($fieldName); } $this->_data[$fieldName] = $value; $this->_modified[] = $fieldName; @@ -1647,7 +1650,7 @@ protected function _isValueModified($type, $old, $new) /** * Places a related component in the object graph. * - * This method inserts a related component instance in this record + * This method inserts a related component instance in this record * relations, populating the foreign keys accordingly. * * @param string $name related component alias in the relation @@ -1657,11 +1660,11 @@ protected function _isValueModified($type, $old, $new) public function coreSetRelated($name, $value) { $rel = $this->_table->getRelation($name); - + if ($value === null) { $value = self::$_null; } - + // one-to-many or one-to-one relation if ($rel instanceof Doctrine_Relation_ForeignKey || $rel instanceof Doctrine_Relation_LocalKey) { if ( ! $rel->isOneToOne()) { @@ -1819,12 +1822,14 @@ public function resetPendingUnlinks() * * this method also saves the related components * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @throws Exception if record is not valid and validation is active * @return void */ - public function save(Doctrine_Connection $conn = null) + public function save($conn = null) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + if ($conn === null) { $conn = $this->_table->getConnection(); } @@ -1837,10 +1842,12 @@ public function save(Doctrine_Connection $conn = null) * throw an exception when validation fails but returns TRUE on * success or FALSE on failure. * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @return TRUE if the record was saved sucessfully without errors, FALSE otherwise. */ - public function trySave(Doctrine_Connection $conn = null) { + public function trySave($conn = null) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + try { $this->save($conn); return true; @@ -1860,14 +1867,16 @@ public function trySave(Doctrine_Connection $conn = null) { * query isemulated through this method for other DBMS using standard types * of queries inside a transaction to assure the atomicity of the operation. * - * @param Doctrine_Connection $conn optional connection parameter + * @param Doctrine_Connection|null $conn optional connection parameter * @throws Doctrine_Connection_Exception if some of the key values was null * @throws Doctrine_Connection_Exception if there were no key fields * @throws Doctrine_Connection_Exception if something fails at database level * @return integer number of rows affected */ - public function replace(Doctrine_Connection $conn = null) + public function replace($conn = null) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + if ($conn === null) { $conn = $this->_table->getConnection(); } @@ -1876,7 +1885,7 @@ public function replace(Doctrine_Connection $conn = null) /** * retrieves an array of modified fields and associated new values. - * + * * @param boolean $old pick the old values (instead of the new ones) * @param boolean $last pick only lastModified values (@see getLastModified()) * @return array $a @@ -1888,8 +1897,8 @@ public function getModified($old = false, $last = false) $modified = $last ? $this->_lastModified:$this->_modified; foreach ($modified as $fieldName) { if ($old) { - $a[$fieldName] = isset($this->_oldValues[$fieldName]) - ? $this->_oldValues[$fieldName] + $a[$fieldName] = isset($this->_oldValues[$fieldName]) + ? $this->_oldValues[$fieldName] : $this->getTable()->getDefaultValueOf($fieldName); } else { $a[$fieldName] = $this->_data[$fieldName]; @@ -1913,7 +1922,7 @@ public function getLastModified($old = false) * Retrieves data prepared for a sql transaction. * * Returns an array of modified fields and values with data preparation; - * adds column aggregation inheritance and converts Records into primary + * adds column aggregation inheritance and converts Records into primary * key values. * * @param array $array @@ -2008,10 +2017,10 @@ public function toArray($deep = true, $prefixKey = false) if ($this->_state == self::STATE_LOCKED || $this->_state == self::STATE_TLOCKED) { return false; } - + $stateBeforeLock = $this->_state; $this->_state = $this->exists() ? self::STATE_LOCKED : self::STATE_TLOCKED; - + $a = array(); foreach ($this as $column => $value) { @@ -2306,8 +2315,10 @@ public function getIterator() * * @return boolean true if successful */ - public function delete(Doctrine_Connection $conn = null) + public function delete($conn = null) { + Types::isNullable('conn', $conn, 'Doctrine_Connection'); + if ($conn == null) { $conn = $this->_table->getConnection(); } @@ -2873,8 +2884,8 @@ protected function _processPendingLinks($alias) } /** - * Reset the modified array and store the old array in lastModified so it - * can be accessed by users after saving a record, since the modified array + * Reset the modified array and store the old array in lastModified so it + * can be accessed by users after saving a record, since the modified array * is reset after the object is saved. * * @return void @@ -2927,7 +2938,7 @@ public function deleteNode() { $this->getNode()->delete(); } - + /** * Helps freeing the memory occupied by the entity. * Cuts all references the entity has to other entities and removes the entity diff --git a/lib/Doctrine/Table.php b/lib/Doctrine/Table.php index 0d3c9f471..557f0b0bb 100644 --- a/lib/Doctrine/Table.php +++ b/lib/Doctrine/Table.php @@ -1,4 +1,7 @@ getErrorStack(); } else { @@ -2191,8 +2196,10 @@ public function removeColumn($fieldName) * * @return array numeric array */ - public function getColumnNames(array $fieldNames = null) + public function getColumnNames($fieldNames = null) { + Types::isNullable('fieldNames', $fieldNames, 'array'); + if ($fieldNames === null) { return array_keys($this->_columns); } else { @@ -2747,10 +2754,10 @@ public function buildFindByWhere($fieldName) $fieldsFound = $matches[1]; $operatorFound = array_map('strtoupper', $matches[2]); - // Check if $fieldName has unidentified parts left + // Check if $fieldName has unidentified parts left if (strlen(implode('', $fieldsFound) . implode('', $operatorFound)) !== strlen($fieldName)) { $expression = preg_replace('/(' . implode('|', $fields) . ')(Or|And)?/', '($1)$2', $fieldName); - throw new Doctrine_Table_Exception('Invalid expression found: ' . $expression); + throw new Doctrine_Table_Exception('Invalid expression found: ' . $expression); } // Build result @@ -2775,7 +2782,7 @@ public function buildFindByWhere($fieldName) } $where .= ' ' . strtoupper($operatorFound[$index]) . ' '; - + $lastOperator = $operatorFound[$index]; } diff --git a/lib/Doctrine/Tree/Interface.php b/lib/Doctrine/Tree/Interface.php index 4a88116c4..f399afebc 100644 --- a/lib/Doctrine/Tree/Interface.php +++ b/lib/Doctrine/Tree/Interface.php @@ -35,9 +35,9 @@ interface Doctrine_Tree_Interface { /** * creates root node from given record or from a new record * - * @param Doctrine_Record $record instance of Doctrine_Record + * @param Doctrine_Record|null $record instance of Doctrine_Record */ - public function createRoot(Doctrine_Record $record = null); + public function createRoot($record = null); /** * returns root node diff --git a/lib/Doctrine/Tree/NestedSet.php b/lib/Doctrine/Tree/NestedSet.php index 30b426f02..e880a887a 100644 --- a/lib/Doctrine/Tree/NestedSet.php +++ b/lib/Doctrine/Tree/NestedSet.php @@ -1,4 +1,7 @@ getAttribute('hasManyRoots')) { if ( ! $record || ( ! $record->exists() && ! $record->getNode()->getRootValue()) || $record->getTable()->isIdentifierComposite()) { @@ -94,14 +99,14 @@ public function createRoot(Doctrine_Record $record = null) . " be created as a root node. Automatic assignment of a root id on" . " transient/new records is no longer supported."); } - + if ($record->exists() && ! $record->getNode()->getRootValue()) { // Default: root_id = id $identifier = $record->getTable()->getIdentifier(); $record->getNode()->setRootValue($record->get($identifier)); } } - + if ( ! $record) { $record = $this->table->create(); } @@ -173,8 +178,8 @@ public function fetchTree($options = array(), $hydrationMode = null) $q->addOrderBy($this->_baseAlias . ".lft ASC"); } - if ( ! is_null($depth)) { - $q->addWhere($this->_baseAlias . ".level BETWEEN ? AND ?", array(0, $depth)); + if ( ! is_null($depth)) { + $q->addWhere($this->_baseAlias . ".level BETWEEN ? AND ?", array(0, $depth)); } $q = $this->returnQueryWithRootId($q, $rootId); @@ -212,8 +217,8 @@ public function fetchBranch($pk, $options = array(), $hydrationMode = null) $q->addWhere($this->_baseAlias . ".lft >= ? AND " . $this->_baseAlias . ".rgt <= ?", $params) ->addOrderBy($this->_baseAlias . ".lft asc"); - if ( ! is_null($depth)) { - $q->addWhere($this->_baseAlias . ".level BETWEEN ? AND ?", array($record->get('level'), $record->get('level')+$depth)); + if ( ! is_null($depth)) { + $q->addWhere($this->_baseAlias . ".level BETWEEN ? AND ?", array($record->get('level'), $record->get('level')+$depth)); } $q = $this->returnQueryWithRootId($q, $record->getNode()->getRootValue()); diff --git a/tests/DoctrineTest/GroupTest.php b/tests/DoctrineTest/GroupTest.php index b4f481463..a224dde30 100644 --- a/tests/DoctrineTest/GroupTest.php +++ b/tests/DoctrineTest/GroupTest.php @@ -1,4 +1,7 @@ array(), 'fails' => array()); @@ -107,7 +110,7 @@ public function assertNotNull($expr) } } - public function pass() + public function pass() { $class = get_class($this); if ( ! isset(self::$_passesAndFails['fails'][$class])) { @@ -118,7 +121,7 @@ public function pass() public function fail($message = "") { - $this->_fail($message); + $this->_fail($message); } public function _fail($message = "") @@ -149,20 +152,22 @@ public function _fail($message = "") self::$_passesAndFails['fails'][$class] = $class; } - public function run(DoctrineTest_Reporter $reporter = null, $filter = null) + public function run($reporter = null, $filter = null) { + Types::isNullable('reporter', $reporter, 'DoctrineTest_Reporter'); + foreach (get_class_methods($this) as $method) { if (substr($method, 0, 4) === 'test') { $this->setUp(); $this->$method(); - + $this->tearDown(); } } } - public function getMessages() + public function getMessages() { return $this->_messages; } diff --git a/tests/Ticket/1830TestCase.php b/tests/Ticket/1830TestCase.php index b9eacf83e..c008881a3 100644 --- a/tests/Ticket/1830TestCase.php +++ b/tests/Ticket/1830TestCase.php @@ -1,5 +1,6 @@ prepareData(); } - public function run(DoctrineTest_Reporter $reporter = null, $filter = null) + public function run($reporter = null, $filter = null) { - parent::run($reporter, $filter); - $this->manager->closeConnection($this->connection); + Types::isNullable('reporter', $reporter, 'DoctrineTest_Reporter'); + + parent::run($reporter, $filter); + $this->manager->closeConnection($this->connection); } - public function prepareData() + public function prepareData() { } - - public function prepareTables() + + public function prepareTables() { try { $this->conn->exec('DROP TABLE ticket_1830__article_translation'); diff --git a/tests/Ticket/1876bTestCase.php b/tests/Ticket/1876bTestCase.php index ed16a1a74..e8566a96a 100644 --- a/tests/Ticket/1876bTestCase.php +++ b/tests/Ticket/1876bTestCase.php @@ -1,5 +1,7 @@ prepareData(); } - public function run(DoctrineTest_Reporter $reporter = null, $filter = null) + public function run($reporter = null, $filter = null) { - parent::run($reporter, $filter); - $this->manager->closeConnection($this->connection); + Types::isNullable('reporter', $reporter, 'DoctrineTest_Reporter'); + + parent::run($reporter, $filter); + $this->manager->closeConnection($this->connection); } - public function prepareData() + public function prepareData() { } - - public function prepareTables() + + public function prepareTables() { try { $this->conn->exec('DROP TABLE t1876b_recipe_ingredient'); @@ -30,11 +34,11 @@ public function prepareTables() $this->conn->exec('DROP TABLE t1876b_company'); } catch(Doctrine_Connection_Exception $e) { } - + $this->tables = array( 'T1876b_Recipe', 'T1876b_Company', 'T1876b_RecipeIngredient' ); - + parent::prepareTables(); } @@ -47,16 +51,16 @@ public function testDuplicatedParamsInSubQuery() $company->name = 'Test Company ' . ($i + 1); $company->save($this->connection); } - + for ($i = 0; $i < 10; $i++) { $recipe = new T1876b_Recipe(); - + $recipe->name = 'test ' . $i; $recipe->company_id = ($i % 3 == 0) ? 1 : 2; $recipe->RecipeIngredients[]->name = 'test'; - + $recipe->save($this->connection); - + if ($i % 2 == 0) { $recipe->delete($this->connection); } @@ -68,14 +72,14 @@ public function testDuplicatedParamsInSubQuery() ->leftJoin('r.Company c') ->leftJoin('r.RecipeIngredients') ->addWhere('c.id = ?', 2); - + $this->assertEqual( - $q->getCountSqlQuery(), + $q->getCountSqlQuery(), 'SELECT COUNT(*) AS num_results FROM (' . 'SELECT t.id FROM t1876b__recipe t ' . 'LEFT JOIN t1876b__company t2 ON t.company_id = t2.id AND t2.deleted_at IS NULL ' . 'LEFT JOIN t1876b__recipe_ingredient t3 ON t.id = t3.recipe_id AND t3.deleted_at IS NULL ' - . 'WHERE t2.id = ? AND (t.deleted_at IS NULL) GROUP BY t.id' + . 'WHERE t2.id = ? AND (t.deleted_at IS NULL) GROUP BY t.id' . ') dctrn_count_query' ); $this->assertEqual($q->count(), 3); @@ -94,11 +98,11 @@ public function setTableDefinition() { $this->hasColumn('company_id', 'integer', null); $this->hasColumn('name', 'string', 255); } - + public function setUp() { $this->hasOne('T1876b_Company as Company', array('local' => 'company_id', 'foreign' => 'id')); $this->hasMany('T1876b_RecipeIngredient as RecipeIngredients', array('local' => 'id', 'foreign' => 'recipe_id')); - + $this->actAs('SoftDelete'); } } @@ -108,10 +112,10 @@ public function setTableDefinition() { $this->hasColumn('id', 'integer', null, array('autoincrement' => true, 'primary' => true)); $this->hasColumn('name', 'string', 255); } - + public function setUp() { $this->hasMany('T1876b_Recipe as Recipes', array('local' => 'id', 'foreign' => 'company_id')); - + $this->actAs('SoftDelete'); } } @@ -122,10 +126,10 @@ public function setTableDefinition() { $this->hasColumn('recipe_id', 'integer', null); $this->hasColumn('name', 'string', 255); } - + public function setUp() { $this->hasOne('T1876b_Recipe as Recipe', array('local' => 'recipe_id', 'foreign' => 'id')); - + $this->actAs('SoftDelete'); } } \ No newline at end of file diff --git a/tests/Ticket/1935TestCase.php b/tests/Ticket/1935TestCase.php index cc8d9470e..bf66a6aaa 100644 --- a/tests/Ticket/1935TestCase.php +++ b/tests/Ticket/1935TestCase.php @@ -1,5 +1,7 @@ prepareData(); } - public function run(DoctrineTest_Reporter $reporter = null, $filter = null) + public function run($reporter = null, $filter = null) { + Types::isNullable('reporter', $reporter, 'DoctrineTest_Reporter'); + parent::run($reporter, $filter); $this->manager->closeConnection($this->connection); }