Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PluginApiExistsLogic
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 validateImpl
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 executeImpl
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Api\PluginApi;
6
7use PeServer\App\Models\AppDatabaseCache;
8use PeServer\App\Models\Domain\Api\ApiLogicBase;
9use PeServer\App\Models\ResponseJson;
10use PeServer\Core\Collection\Arr;
11use PeServer\Core\Collection\Collections;
12use PeServer\Core\Text;
13use PeServer\Core\Mvc\LogicCallMode;
14use PeServer\Core\Mvc\LogicParameter;
15use PeServer\Core\Uuid;
16
17class PluginApiExistsLogic extends ApiLogicBase
18{
19    public function __construct(LogicParameter $parameter, private AppDatabaseCache $dbCache)
20    {
21        parent::__construct($parameter);
22    }
23
24    #region ApiLogicBase
25
26    protected function validateImpl(LogicCallMode $callMode): void
27    {
28        //NOP
29    }
30
31    protected function executeImpl(LogicCallMode $callMode): void
32    {
33        $json = $this->getRequestJson();
34        $pluginId = $json['plugin_id'] ?? Text::EMPTY;
35        $pluginName = $json['plugin_name'] ?? Text::EMPTY;
36
37        $plugins = $this->dbCache->readPluginInformation();
38        $pluginCollection = Collections::from($plugins->items);
39        $existsPluginId = $pluginCollection->any(function ($i) use ($pluginId) {
40            return Uuid::isEqualGuid($i->pluginId, $pluginId);
41        });
42        $existsPluginName = $pluginCollection->any(function ($i) use ($pluginName) {
43            return $i->pluginName === $pluginName;
44        });
45
46        $this->setResponseJson(ResponseJson::success([
47            'plugin_id' => $existsPluginId,
48            'plugin_name' => $existsPluginName,
49        ]));
50    }
51
52    #endregion
53}