Issues (14)

src/Model/ConfigRepository.php (1 issue)

1
<?php
2
3
namespace Firegento\DevDashboard\Model;
4
5
use Firegento\DevDashboard\Api\Data\ConfigInterface;
6
use Firegento\DevDashboard\Model\ResourceModel\Config\CollectionFactory;
7
use Magento\Framework\Exception\CouldNotSaveException;
8
use Magento\Framework\Model\AbstractModel;
9
10
class ConfigRepository implements \Firegento\DevDashboard\Api\ConfigRepositoryInterface
11
{
12
    protected $objectFactory;
13
    protected $collectionFactory;
14
    /**
15
     * @var ResourceModel\Config
16
     */
17
    private $resource;
18
19
    public function __construct(
20
        ConfigFactory $objectFactory,
21
        CollectionFactory $collectionFactory,
22
        ResourceModel\Config $resource
23
    ) {
24
        $this->objectFactory = $objectFactory;
25
        $this->collectionFactory = $collectionFactory;
26
        $this->resource = $resource;
27
    }
28
29
    /**
30
     * @param ConfigInterface|AbstractModel $object
31
     * @return ConfigInterface
32
     * @throws CouldNotSaveException
33
     */
34
    public function save(ConfigInterface $object)
35
    {
36
        try {
37
            $this->resource->save($object);
38
        } catch (\Exception $e) {
39
            throw new CouldNotSaveException(__($e->getMessage()));
40
        }
41
42
        return $object;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $object returns the type Magento\Framework\Model\AbstractModel which is incompatible with the documented return type Firegento\DevDashboard\Api\Data\ConfigInterface.
Loading history...
43
    }
44
45
    /**
46
     * @param int $userId
47
     * @return Config
48
     */
49
    public function getByUserId($userId)
50
    {
51
        /** @var \Firegento\DevDashboard\Model\Config $object */
52
        $object = $this->objectFactory->create();
53
        $this->resource->load($object, $userId, 'user_id');
54
        $object->setData('user_id', $userId);
55
        return $object;
56
    }
57
}
58