Passed
Push — master ( 082719...4cfd25 )
by Mage
09:49
created

FaqGroup   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
B resolve() 0 36 9
A getGroupIcon() 0 6 1
1
<?php
2
3
namespace Mageprince\Faq\Model\Resolver;
4
5
use Magento\Framework\Data\Collection as AbstractDbCollection;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\Data\Collection 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...
6
use Magento\Framework\GraphQl\Config\Element\Field;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\GraphQl\Config\Element\Field 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...
7
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\GraphQ...n\GraphQlInputException 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...
8
use Magento\Framework\GraphQl\Query\ResolverInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\GraphQl\Query\ResolverInterface 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...
9
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\GraphQl\Schema\Type\ResolveInfo 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...
10
use Magento\Framework\UrlInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Framework\UrlInterface 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...
11
use Magento\Store\Model\StoreManagerInterface;
0 ignored issues
show
Bug introduced by
The type Magento\Store\Model\StoreManagerInterface 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...
12
use Mageprince\Faq\Model\Config\DefaultConfig;
13
use Mageprince\Faq\Model\ResourceModel\FaqGroup\CollectionFactory as FaqGroupCollectionFactory;
0 ignored issues
show
Bug introduced by
The type Mageprince\Faq\Model\Res...Group\CollectionFactory 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...
14
15
class FaqGroup implements ResolverInterface
16
{
17
    /**
18
     * @var FaqGroupCollectionFactory
19
     */
20
    protected $faqGroupCollectionFactory;
21
22
    /**
23
     * @var StoreManagerInterface
24
     */
25
    protected $storeManager;
26
27
    /**
28
     * FaqGroup constructor.
29
     * @param FaqGroupCollectionFactory $faqGroupCollectionFactory
30
     * @param StoreManagerInterface $storeManager
31
     */
32
    public function __construct(
33
        FaqGroupCollectionFactory $faqGroupCollectionFactory,
34
        StoreManagerInterface $storeManager
35
    ) {
36
        $this->faqGroupCollectionFactory = $faqGroupCollectionFactory;
37
        $this->storeManager = $storeManager;
38
    }
39
40
    /**
41
     * @inheritdoc
42
     */
43
    public function resolve(
44
        Field $field,
45
        $context,
46
        ResolveInfo $info,
47
        array $value = null,
48
        array $args = null
49
    ) {
50
        if (isset($args['pageSize']) && $args['pageSize'] < 1) {
51
            throw new GraphQlInputException(__('pageSize value must be greater than 0.'));
0 ignored issues
show
Bug introduced by
The function __ was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

51
            throw new GraphQlInputException(/** @scrutinizer ignore-call */ __('pageSize value must be greater than 0.'));
Loading history...
52
        }
53
54
        if (isset($args['currentPage']) && $args['currentPage'] < 1) {
55
            throw new GraphQlInputException(__('currentPage value must be greater than 0.'));
56
        }
57
58
        /** @var \Mageprince\Faq\Model\ResourceModel\FaqGroup\Collection $faqGroupCollection */
59
        $faqGroupCollection = $this->faqGroupCollectionFactory->create();
60
        $faqGroupCollection->addFieldToFilter('status', 1);
61
        $faqGroupCollection->setOrder('sortorder', AbstractDbCollection::SORT_ORDER_ASC);
62
63
        if (isset($args['pageSize'])) {
64
            $faqGroupCollection->setPageSize($args['pageSize']);
65
        }
66
67
        if (isset($args['currentPage'])) {
68
            $faqGroupCollection->setCurPage($args['currentPage']);
69
        }
70
71
        $groups = $faqGroupCollection->getData();
72
        foreach ($groups as $key => $group) {
73
            if ($icon = $group['icon']) {
74
                $groups[$key]['icon'] = $this->getGroupIcon($icon);
75
            }
76
        }
77
78
        return $groups;
79
    }
80
81
    /**
82
     * Retrieve group icon url
83
     *
84
     * @param string $icon
85
     * @return string
86
     * @throws \Magento\Framework\Exception\NoSuchEntityException
87
     */
88
    public function getGroupIcon($icon)
89
    {
90
        $mediaUrl = $this->storeManager
91
            ->getStore()
92
            ->getBaseUrl(UrlInterface::URL_TYPE_MEDIA);
93
        return $mediaUrl . DefaultConfig::ICON_TMP_PATH . $icon;
94
    }
95
}
96