@@ -56,13 +56,13 @@ class Command extends Component
5656
5757 /**
5858 * Enables query cache for this command.
59- * @param int $duration the number of seconds that query result of this command can remain valid in the cache.
59+ * @param int|null $duration the number of seconds that query result of this command can remain valid in the cache.
6060 * If this is not set, the value of [[Connection::queryCacheDuration]] will be used instead.
6161 * Use 0 to indicate that the cached data will never expire.
62- * @param \yii\caching\Dependency $dependency the cache dependency associated with the cached query result.
62+ * @param \yii\caching\Dependency|null $dependency the cache dependency associated with the cached query result.
6363 * @return $this the command object itself
6464 */
65- public function cache ($ duration = null , $ dependency = null )
65+ public function cache (int $ duration = null , \ yii \ caching \ Dependency $ dependency = null ): Command
6666 {
6767 $ this ->queryCacheDuration = $ duration === null ? $ this ->db ->queryCacheDuration : $ duration ;
6868 $ this ->queryCacheDependency = $ dependency ;
@@ -73,7 +73,7 @@ public function cache($duration = null, $dependency = null)
7373 * Disables query cache for this command.
7474 * @return $this the command object itself
7575 */
76- public function noCache ()
76+ public function noCache (): Command
7777 {
7878 $ this ->queryCacheDuration = -1 ;
7979 return $ this ;
@@ -85,7 +85,7 @@ public function noCache()
8585 * It is likely that this method returns an invalid URL due to improper replacement of parameter placeholders.
8686 * @return string the raw URL with parameter values inserted into the corresponding placeholders.
8787 */
88- public function getRawUrl ()
88+ public function getRawUrl (): string
8989 {
9090 $ rawUrl = $ this ->db ->handler ->get ($ this ->pathInfo , $ this ->queryParams )->fullUrl ;
9191
@@ -94,29 +94,30 @@ public function getRawUrl()
9494
9595 /**
9696 * Executes the SQL statement and returns ALL rows at once.
97- * @param int $fetchMode for compatibility with [[\yii\db\Command]]
97+ * @param int|null $fetchMode for compatibility with [[\yii\db\Command]]
9898 * @return array all rows of the query result. Each array element is an array representing a row of data.
9999 * An empty array is returned if the query results in nothing.
100100 * @throws \yii\base\InvalidConfigException
101101 */
102- public function queryAll ($ fetchMode = null )
102+ public function queryAll (int $ fetchMode = null ): array
103103 {
104104 return $ this ->queryInternal ();
105105 }
106106
107107 /**
108108 * Executes the SQL statement and returns the first row of the result.
109109 * This method is best used when only the first row of result is needed for a query.
110- * @param int $fetchMode for compatibility with [[\yii\db\Command]]
110+ * @param int|null $fetchMode for compatibility with [[\yii\db\Command]]
111111 * @return array|false the first row (in terms of an array) of the query result. False is returned if the query
112112 * results in nothing.
113+ * @throws \yii\base\InvalidConfigException
113114 */
114- public function queryOne ($ fetchMode = null )
115+ public function queryOne (int $ fetchMode = null )
115116 {
116- /* @var $class ActiveRecord */
117117 $ class = $ this ->modelClass ;
118118
119119 if (!empty ($ class ) && class_exists ($ class )) {
120+ /* @var $class ActiveRecord */
120121 $ pks = $ class ::primaryKey ();
121122
122123 if (count ($ pks ) === 1 && isset ($ this ->queryParams ['filter ' ])) {
@@ -138,7 +139,7 @@ public function queryOne($fetchMode = null)
138139 *
139140 * @return mixed
140141 */
141- public function execute ($ method = 'get ' )
142+ public function execute (string $ method = 'get ' )
142143 {
143144 return $ this ->queryInternal ($ method );
144145 }
@@ -152,7 +153,7 @@ public function execute($method = 'get')
152153 * @return mixed
153154 * @throws Exception
154155 */
155- public function insert ($ model , $ columns )
156+ public function insert (string $ model , array $ columns )
156157 {
157158 $ this ->pathInfo = $ model ;
158159
@@ -164,12 +165,11 @@ public function insert($model, $columns)
164165 *
165166 * @param string $model
166167 * @param array $data
167- * @param string $id
168+ * @param string|null $id
168169 *
169170 * @return mixed
170- * @throws Exception
171171 */
172- public function update ($ model , $ data = [], $ id = null )
172+ public function update (string $ model , array $ data = [], string $ id = null )
173173 {
174174 $ method = $ this ->db ->updateMethod ;
175175 $ this ->pathInfo = $ model ;
@@ -184,12 +184,12 @@ public function update($model, $data = [], $id = null)
184184 * Deletes a record
185185 *
186186 * @param string $model
187- * @param string $id
187+ * @param string|null $id
188188 *
189189 * @return mixed
190190 * @throws Exception
191191 */
192- public function delete ($ model , $ id = null )
192+ public function delete (string $ model , string $ id = null )
193193 {
194194 $ this ->pathInfo = $ model ;
195195 if ($ id ) {
@@ -206,7 +206,7 @@ public function delete($model, $id = null)
206206 *
207207 * @return mixed
208208 */
209- protected function queryInternal ($ method = 'get ' )
209+ protected function queryInternal (string $ method = 'get ' )
210210 {
211211 if ($ this ->db ->usePluralisation && strpos ($ this ->pathInfo , '/ ' ) === false ) {
212212 $ this ->pathInfo = Inflector::pluralize ($ this ->pathInfo );
@@ -246,7 +246,7 @@ protected function queryInternal($method = 'get')
246246 * @return array the cache key
247247 * @since 2.0.16
248248 */
249- protected function getCacheKey ($ method )
249+ protected function getCacheKey (string $ method ): array
250250 {
251251 return [
252252 __CLASS__ ,
0 commit comments