99use Cake \Datasource \EntityInterface ;
1010use Cake \Event \EventInterface ;
1111use Cake \ORM \Behavior ;
12- use Cake \ORM \Query ;
12+ use Cake \ORM \Query \ SelectQuery ;
1313
1414/**
1515 * SequenceBehavior maintains a contiguous sequence of integers (starting at 1
@@ -67,7 +67,7 @@ class SequenceBehavior extends Behavior
6767 *
6868 * @var array<string, mixed>
6969 */
70- protected $ _defaultConfig = [
70+ protected array $ _defaultConfig = [
7171 'sequenceField ' => 'position ' ,
7272 'scope ' => [],
7373 'startAt ' => 1 ,
@@ -78,7 +78,7 @@ class SequenceBehavior extends Behavior
7878 *
7979 * @var array|null
8080 */
81- protected $ _oldValues ;
81+ protected ? array $ _oldValues = null ;
8282
8383 /**
8484 * Normalize config options.
@@ -108,14 +108,14 @@ public function initialize(array $config): void
108108 * Adds order value if not already set in query.
109109 *
110110 * @param \Cake\Event\EventInterface $event The beforeFind event that was fired.
111- * @param \Cake\ORM\Query $query The query object.
111+ * @param \Cake\ORM\Query\SelectQuery $query The query object.
112112 * @param \ArrayObject<string, mixed> $options The options passed to the find method.
113113 * @return void
114114 */
115- public function beforeFind (EventInterface $ event , Query $ query , ArrayObject $ options ): void
115+ public function beforeFind (EventInterface $ event , SelectQuery $ query , ArrayObject $ options ): void
116116 {
117117 if (!$ query ->clause ('order ' )) {
118- $ query ->order ([$ this ->_table ->aliasField ($ this ->_config ['sequenceField ' ]) => 'ASC ' ]);
118+ $ query ->orderBy ([$ this ->_table ->aliasField ($ this ->_config ['sequenceField ' ]) => 'ASC ' ]);
119119 }
120120 }
121121
@@ -250,7 +250,7 @@ public function beforeDelete(EventInterface $event, EntityInterface $entity): vo
250250 * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved.
251251 * @return void
252252 */
253- public function afterDelete (EventInterface $ event , EntityInterface $ entity )
253+ public function afterDelete (EventInterface $ event , EntityInterface $ entity ): void
254254 {
255255 if (!$ this ->_oldValues ) {
256256 return ;
@@ -276,7 +276,7 @@ public function afterDelete(EventInterface $event, EntityInterface $entity)
276276 * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved.
277277 * @return bool
278278 */
279- public function moveUp (EntityInterface $ entity )
279+ public function moveUp (EntityInterface $ entity ): bool
280280 {
281281 return $ this ->_movePosition ($ entity , '- ' );
282282 }
@@ -289,7 +289,7 @@ public function moveUp(EntityInterface $entity)
289289 * @param \Cake\Datasource\EntityInterface $entity The entity that is going to be saved.
290290 * @return bool
291291 */
292- public function moveDown (EntityInterface $ entity )
292+ public function moveDown (EntityInterface $ entity ): bool
293293 {
294294 return $ this ->_movePosition ($ entity , '+ ' );
295295 }
@@ -448,7 +448,7 @@ protected function _getOldValues(EntityInterface $entity): array
448448 * @phpstan-ignore-next-line
449449 */
450450 $ primaryKey = $ entity ->get ($ this ->_table ->getPrimaryKey ());
451- $ entity = $ this ->_table ->get ($ primaryKey , [ ' fields ' => $ fields] );
451+ $ entity = $ this ->_table ->get ($ primaryKey , fields: $ fields );
452452 $ values = $ entity ->extract ($ fields );
453453 }
454454
@@ -471,7 +471,7 @@ protected function _getOldValues(EntityInterface $entity): array
471471 * @param \Cake\Datasource\EntityInterface $entity Entity.
472472 * @return array|false
473473 */
474- protected function _getScope (EntityInterface $ entity )
474+ protected function _getScope (EntityInterface $ entity ): array | false
475475 {
476476 $ scope = [];
477477 $ config = $ this ->getConfig ();
@@ -504,15 +504,15 @@ protected function _getScope(EntityInterface $entity)
504504 * @param array $scope Array with scope field => scope values, used for conditions.
505505 * @return int Value of order field of last record in set
506506 */
507- protected function _getHighestOrder (array $ scope = [] ): int
507+ protected function _getHighestOrder (array $ scope ): int
508508 {
509509 $ orderField = $ this ->_config ['sequenceField ' ];
510510
511511 // Find the last record in the set
512512 $ last = $ this ->_table ->find ()
513513 ->select ([$ orderField ])
514514 ->where ($ scope )
515- ->order ([$ orderField => 'DESC ' ])
515+ ->orderBy ([$ orderField => 'DESC ' ])
516516 ->limit (1 )
517517 ->enableHydration (false )
518518 ->first ();
@@ -554,7 +554,7 @@ protected function _getUpdateExpression(string $direction = '+'): QueryExpressio
554554 {
555555 $ field = $ this ->_config ['sequenceField ' ];
556556
557- return $ this ->_table ->query ()->newExpr ()
557+ return $ this ->_table ->selectQuery ()->newExpr ()
558558 ->add (new IdentifierExpression ($ field ))
559559 ->add ('1 ' )
560560 ->setConjunction ($ direction );
0 commit comments