PickUpStores   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A vaildateArgs() 0 8 5
A resolve() 0 13 1
A __construct() 0 4 1
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\Resolver;
26
27
use LarsRoettig\GraphQLStorePickup\Api\StoreRepositoryInterface;
28
use LarsRoettig\GraphQLStorePickup\Model\Store\GetList;
29
use Magento\Framework\GraphQl\Config\Element\Field;
30
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
31
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder as SearchCriteriaBuilder;
32
use Magento\Framework\GraphQl\Query\ResolverInterface;
33
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
34
35
class PickUpStores implements ResolverInterface
36
{
37
38
    /**
39
     * @var GetListInterface
0 ignored issues
show
Bug introduced by
The type LarsRoettig\GraphQLStore...solver\GetListInterface 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...
40
     */
41
    private $storeRepository;
42
    /**
43
     * @var SearchCriteriaBuilder
44
     */
45
    private $searchCriteriaBuilder;
46
47
    /**
48
     * PickUpStoresList constructor.
49
     * @param GetList $storeRepository
50
     * @param SearchCriteriaBuilder $searchCriteriaBuilder
51
     */
52
    public function __construct(StoreRepositoryInterface $storeRepository, SearchCriteriaBuilder $searchCriteriaBuilder)
53
    {
54
        $this->storeRepository = $storeRepository;
0 ignored issues
show
Documentation Bug introduced by
It seems like $storeRepository of type LarsRoettig\GraphQLStore...toreRepositoryInterface is incompatible with the declared type LarsRoettig\GraphQLStore...solver\GetListInterface of property $storeRepository.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
        $this->searchCriteriaBuilder = $searchCriteriaBuilder;
56
    }
57
58
    /**
59
     * @inheritdoc
60
     */
61
    public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
62
    {
63
64
        $this->vaildateArgs($args);
0 ignored issues
show
Bug introduced by
It seems like $args can also be of type null; however, parameter $args of LarsRoettig\GraphQLStore...pStores::vaildateArgs() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

64
        $this->vaildateArgs(/** @scrutinizer ignore-type */ $args);
Loading history...
65
66
        $searchCriteria = $this->searchCriteriaBuilder->build('pickup_stores', $args);
67
        $searchCriteria->setCurrentPage($args['currentPage']);
68
        $searchCriteria->setPageSize($args['pageSize']);
69
        $searchResult = $this->storeRepository->getList($searchCriteria);
70
71
        return [
72
            'total_count' => $searchResult->getTotalCount(),
73
            'items' => $searchResult->getItems(),
74
        ];
75
    }
76
77
    /**
78
     * @param array $args
79
     * @throws GraphQlInputException
80
     */
81
    private function vaildateArgs(array $args): void
82
    {
83
        if (isset($args['currentPage']) && $args['currentPage'] < 1) {
84
            throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
85
        }
86
87
        if (isset($args['pageSize']) && $args['pageSize'] < 1) {
88
            throw new GraphQlInputException(__('pageSize value must be greater than 0.'));
89
        }
90
    }
91
}
92