vendor/crehler/shopping-list/ShoppingList/ShoppingListCollection.php line 28

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. /**
  3.  * @copyright 2020 Crehler Sp. z o. o. <https://crehler.com>
  4.  *
  5.  * @author    Jakub MedyƄski <jme@crehler.com>
  6.  * @support   Crehler <support@crehler.com>
  7.  * @created   14 maj 2020
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Crehler\ShoppingList\ShoppingList;
  13. use Shopware\Core\Framework\DataAbstractionLayer\EntityCollection;
  14. /**
  15.  * @method void                     add(ShoppingListEntity $entity)
  16.  * @method void                     set(string $key, ShoppingListEntity $entity)
  17.  * @method ShoppingListEntity[]     getIterator()
  18.  * @method ShoppingListEntity[]     getElements()
  19.  * @method ShoppingListEntity|null  get(string $key)
  20.  * @method ShoppingListEntity|null  first()
  21.  * @method ShoppingListEntity|null  last()
  22.  */
  23. class ShoppingListCollection extends EntityCollection
  24. {
  25.     protected function getExpectedClass(): string
  26.     {
  27.         return ShoppingListEntity::class;
  28.     }
  29.     public function sortByLatest(): void
  30.     {
  31.         $this->sort(function (ShoppingListEntity $aShoppingListEntity $b) {
  32.             $aTime $a->getUpdatedAt() ?? $a->getCreatedAt();
  33.             $bTime $b->getUpdatedAt() ?? $b->getCreatedAt();
  34.             return $aTime $bTime;
  35.         });
  36.     }
  37. }