StoreRepository   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 67
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 6 2
A __construct() 0 12 1
A getList() 0 16 2
1
<?php
2
/**
3
 * Copyright (c) 2019 Lars Roettig
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in all
13
 * copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
 * SOFTWARE.
22
 */
23
declare(strict_types=1);
24
25
namespace LarsRoettig\GraphQLStorePickup\Model;
26
27
use LarsRoettig\GraphQLStorePickup\Api\Data\StoreInterface;
28
use LarsRoettig\GraphQLStorePickup\Api\StoreRepositoryInterface;
29
use LarsRoettig\GraphQLStorePickup\Model\ResourceModel\Store as StoreResourceModel;
30
use LarsRoettig\GraphQLStorePickup\Model\ResourceModel\StoreCollection;
31
use LarsRoettig\GraphQLStorePickup\Model\ResourceModel\StoreCollectionFactory;
0 ignored issues
show
Bug introduced by
The type LarsRoettig\GraphQLStore...\StoreCollectionFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
32
use Magento\Framework\Api\Search\SearchCriteriaBuilder;
33
use Magento\Framework\Api\SearchCriteria\CollectionProcessorInterface;
34
use Magento\Framework\Api\SearchCriteriaInterface;
35
use Magento\Framework\Api\SearchResultsInterface;
36
use Magento\Framework\Api\SearchResultsInterfaceFactory;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Api\Se...ResultsInterfaceFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
use Magento\Framework\Exception\CouldNotSaveException;
38
39
class StoreRepository implements StoreRepositoryInterface
40
{
41
    /**
42
     * @var StoreCollectionFactory
43
     */
44
    private $storeCollectionFactory;
45
    /**
46
     * @var CollectionProcessorInterface
47
     */
48
    private $collectionProcessor;
49
    /**
50
     * @var SearchCriteriaBuilder
51
     */
52
    private $searchCriteriaBuilder;
53
    /**
54
     * @var SearchResultsInterfaceFactory
55
     */
56
    private $storeSearchResultsInterfaceFactory;
57
    /**
58
     * @var StoreResourceModel
59
     */
60
    private $storeResourceModel;
61
62
    public function __construct(
63
        StoreCollectionFactory $storeCollectionFactory,
64
        CollectionProcessorInterface $collectionProcessor,
65
        SearchCriteriaBuilder $searchCriteriaBuilder,
66
        SearchResultsInterfaceFactory $storeSearchResultsInterfaceFactory,
67
        StoreResourceModel $storeResourceModel
68
    ) {
69
        $this->storeCollectionFactory = $storeCollectionFactory;
70
        $this->collectionProcessor = $collectionProcessor;
71
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
72
        $this->storeSearchResultsInterfaceFactory = $storeSearchResultsInterfaceFactory;
73
        $this->storeResourceModel = $storeResourceModel;
74
    }
75
76
    /**
77
     * @inheritDoc
78
     */
79
    public function getList(SearchCriteriaInterface $searchCriteria = null): SearchResultsInterface
80
    {
81
        /** @var StoreCollection $storeCollection */
82
        $storeCollection = $this->storeCollectionFactory->create();
83
        if (null === $searchCriteria) {
84
            $searchCriteria = $this->searchCriteriaBuilder->create();
85
        } else {
86
            $this->collectionProcessor->process($searchCriteria, $storeCollection);
87
        }
88
        /** @var SearchResultsInterface $searchResult */
89
        $searchResult = $this->storeSearchResultsInterfaceFactory->create();
90
        $searchResult->setItems($storeCollection->getItems());
91
        $searchResult->setTotalCount($storeCollection->getSize());
92
        $searchResult->setSearchCriteria($searchCriteria);
93
94
        return $searchResult;
95
    }
96
97
    /**
98
     * @inheritDoc
99
     */
100
    public function save(StoreInterface $store): void
101
    {
102
        try {
103
            $this->storeResourceModel->save($store);
104
        } catch (\Exception $e) {
105
            throw new CouldNotSaveException(__('Could not save Source'), $e);
106
        }
107
    }
108
}
109