Passed
Push — master ( ca7167...276d5c )
by Fabian
06:10
created

ConfigRepository::getByUserId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Firegento\DevDashboard\Model;
4
5
use Firegento\DevDashboard\Api\Data\ConfigInterface;
6
use Firegento\DevDashboard\Model\ConfigFactory;
0 ignored issues
show
Bug introduced by
The type Firegento\DevDashboard\Model\ConfigFactory 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 Firegento\DevDashboard\Model\ResourceModel\Config\CollectionFactory;
0 ignored issues
show
Bug introduced by
The type Firegento\DevDashboard\M...onfig\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...
8
9
use Magento\Framework\Exception\CouldNotSaveException;
10
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...
11
12
class ConfigRepository implements \Firegento\DevDashboard\Api\ConfigRepositoryInterface
13
{
14
    protected $objectFactory;
15
    protected $collectionFactory;
16
17
    public function __construct(
18
        ConfigFactory $objectFactory,
19
        CollectionFactory $collectionFactory,
20
        SearchResultsInterfaceFactory $searchResultsFactory
21
    )
22
    {
23
        $this->objectFactory = $objectFactory;
24
        $this->collectionFactory = $collectionFactory;
25
        $this->searchResultsFactory = $searchResultsFactory;
0 ignored issues
show
Bug Best Practice introduced by
The property searchResultsFactory does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
    }
27
28
    /**
29
     * @param ConfigInterface $object
30
     * @return ConfigInterface
31
     * @throws CouldNotSaveException
32
     */
33
    public function save(ConfigInterface $object)
34
    {
35
        try {
36
            $object->save();
0 ignored issues
show
Bug introduced by
The method save() does not exist on Firegento\DevDashboard\Api\Data\ConfigInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to Firegento\DevDashboard\Api\Data\ConfigInterface. ( Ignorable by Annotation )

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

36
            $object->/** @scrutinizer ignore-call */ 
37
                     save();
Loading history...
37
        } catch (\Exception $e) {
38
            throw new CouldNotSaveException(__($e->getMessage()));
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

38
            throw new CouldNotSaveException(/** @scrutinizer ignore-call */ __($e->getMessage()));
Loading history...
39
        }
40
        return $object;
41
    }
42
43
    /**
44
     * @param int $user_id
45
     * @return Config
46
     */
47
    public function getByUserId($user_id)
48
    {
49
        /** @var \Firegento\DevDashboard\Model\Config $object */
50
        $object = $this->objectFactory->create();
51
        $object->load($user_id, 'user_id');
0 ignored issues
show
Deprecated Code introduced by
The function Magento\Framework\Model\AbstractModel::load() has been deprecated: 100.1.0 because entities must not be responsible for their own loading. Service contracts should persist entities. Use resource model "load" or collections to implement service contract model loading operations. ( Ignorable by Annotation )

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

51
        /** @scrutinizer ignore-deprecated */ $object->load($user_id, 'user_id');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
52
        return $object;
53
    }
54
55
}