Options::toOptionArray()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 12

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
dl 12
loc 12
rs 9.8666
c 0
b 0
f 0
cc 4
nc 2
nop 0
1
<?php
2
namespace LizardMedia\CronScheduler\Ui\Component\Column\Code;
3
4
use Magento\Cron\Model\ConfigInterface;
5
use Magento\Framework\Data\OptionSourceInterface;
6
7
/**
8
 * Class Options
9
 * @package LizardMedia\CronScheduler\Ui\Component\Column\Code
10
 */
11 View Code Duplication
class Options implements OptionSourceInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    /**
14
     * @var array
15
     */
16
    protected $options = [];
17
18
    /**
19
     * @var ConfigInterface
20
     */
21
    private $cronConfig;
22
23
    /**
24
     * Options constructor.
25
     * @param ConfigInterface $cronConfig
26
     */
27
    public function __construct(
28
        ConfigInterface $cronConfig
29
    ) {
30
        $this->cronConfig = $cronConfig;
31
    }
32
33
    /**
34
     * Get all options available
35
     * @return array
36
     */
37
    public function toOptionArray()
38
    {
39
        if (empty($this->options)) {
40
            $cronConfigJobs = $this->cronConfig->getJobs();
41
            foreach (array_values($cronConfigJobs) as $jobs) {
42
                foreach (array_keys($jobs) as $code) {
43
                    array_push($this->options, ['label' => $code, 'value' => $code]);
44
                }
45
            }
46
        }
47
        return $this->options;
48
    }
49
}
50