Issues (3)

Console/Command/Repository.php (1 issue)

1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Command Class
6
 * @category    Ticaje
7
 * @package     Ticaje_Dummy
8
 * @author      Hector Luis Barrientos <[email protected]>
9
 */
10
11
namespace Ticaje\Dummy\Console\Command;
12
13
use Magento\Framework\Api\SearchCriteriaBuilder;
14
use Magento\Framework\ObjectManagerInterface;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
use Ticaje\Base\Repository\Base\BaseRepositoryInterface;
0 ignored issues
show
The type Ticaje\Base\Repository\B...BaseRepositoryInterface 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...
20
21
/**
22
 * Class Repository
23
 * @package Ticaje\Dummy\Console\Command
24
 */
25
class Repository extends Command
26
{
27
    private $dummyRepository;
28
29
    private $om;
30
31
    public function __construct(
32
        BaseRepositoryInterface $dummyRepository,
33
        ObjectManagerInterface $objectManager,
34
        string $name = null
35
    ) {
36
        $this->dummyRepository = $dummyRepository;
37
        $this->om = $objectManager;
38
        parent::__construct($name);
39
    }
40
41
    protected function configure()
42
    {
43
        $this->setName("ticaje:test:repository");
44
        $this->setDescription("A command the programmer was too lazy to enter a description for.");
45
        parent::configure();
46
    }
47
48
    protected function execute(InputInterface $input, OutputInterface $output)
49
    {
50
        $output->writeln("Starting command...");
51
        $this->launch($output);
52
        $output->writeln("Finishing command...");
53
    }
54
55
    /**
56
     * @param OutputInterface $output
57
     * Creating room for launching any repository method
58
     * @todo Refactor later on
59
     */
60
    protected function launch(OutputInterface $output)
61
    {
62
        $output->writeln("Launching repository command...");
63
        $this->getSingle();
64
    }
65
66
    protected function getList()
67
    {
68
        $criteriaBuilder = $this->om->get(SearchCriteriaBuilder::class);
69
        $criteriaBuilder->addFilter('reference_id', 3);
70
        $criteria = $criteriaBuilder->create();
71
        $list = $this->dummyRepository->getList($criteria);
72
        $item = $list->getTotalCount() > 0 ? $list->getItems()[0]->getData() : null;
73
        print_r($item);
74
    }
75
76
    protected function getSingle()
77
    {
78
        $criteriaBuilder = $this->om->get(SearchCriteriaBuilder::class);
79
        $criteriaBuilder->addFilter('reference_id', 3);
80
        $criteria = $criteriaBuilder->create();
81
        $single = $this->dummyRepository->getSingle($criteria);
82
        print_r($single ? $single->getData() : 'Not Found');
83
    }
84
85
    protected function getById()
86
    {
87
        $object = $this->dummyRepository->getById(3);
88
        print_r($object ? $object->getData() : 'Not Found');
89
    }
90
91
    protected function deleteById()
92
    {
93
        $delete = $this->dummyRepository->deleteById(1);
94
        print_r($delete);
95
    }
96
}
97