Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PluginDetailLogic
0.00% covered (danger)
0.00%
0 / 16
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 executeImpl
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Plugin;
6
7use PeServer\App\Models\AppDatabaseCache;
8use PeServer\App\Models\Cache\PluginCacheCategory;
9use PeServer\App\Models\Cache\PluginCacheItem;
10use PeServer\App\Models\Domain\Page\PageLogicBase;
11use PeServer\Core\Collection\Arr;
12use PeServer\Core\Collection\Collections;
13use PeServer\Core\Mvc\LogicCallMode;
14use PeServer\Core\Mvc\LogicParameter;
15use PeServer\Core\Uuid;
16
17class PluginDetailLogic extends PageLogicBase
18{
19    public function __construct(LogicParameter $parameter, private AppDatabaseCache $dbCache)
20    {
21        parent::__construct($parameter);
22    }
23
24    protected function validateImpl(LogicCallMode $callMode): void
25    {
26        //NOP
27    }
28
29    protected function executeImpl(LogicCallMode $callMode): void
30    {
31        $pluginInformation = $this->dbCache->readPluginInformation();
32        /** @var PluginCacheItem */
33        $plugin = Collections::from($pluginInformation->items)
34            ->first(function ($i) {
35                return Uuid::isEqualGuid($i->pluginId, $this->getRequest('plugin_id'));
36            });
37
38        $categories = Collections::from($pluginInformation->categories)
39            ->where(fn(PluginCacheCategory $i) => Arr::in($plugin->categoryIds, $i->categoryId))
40            ->toArray()
41        ;
42        $categories = Arr::sortCallbackByValue($categories, function (PluginCacheCategory $a, PluginCacheCategory $b) {
43            return $a->categoryName <=> $b->categoryName;
44        });
45
46        $this->setValue('plugin', $plugin);
47        $this->setValue('categories', $categories);
48    }
49}