ConfigResolver::resolveSchedulerClass()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php namespace Indatus\Dispatcher;
2
3
/**
4
 * This file is part of Dispatcher
5
 *
6
 * (c) Ben Kuhl <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
use Illuminate\Contracts\Config\Repository;
13
use Illuminate\Contracts\Container\Container;
14
use ReflectionException;
15
16
class ConfigResolver
17
{
18
    /** @var Repository */
19
    protected $config;
20
21
    /** @var Container */
22
    protected $container;
23
24 94
    public function __construct(Repository $config, Container $container)
25
    {
26 94
        $this->config = $config;
27 94
        $this->container = $container;
28 94
    }
29
30
    /**
31
     * Resolve a class based on the driver configuration
32
     *
33
     * @return \Indatus\Dispatcher\Scheduling\Schedulable
34
     */
35 7
    public function resolveSchedulerClass()
36
    {
37
        try {
38 7
            return $this->container->make($this->getDriver().'\\Scheduler', [$this]);
39 7
        } catch (ReflectionException $e) {
40 7
            return $this->container->make('Indatus\Dispatcher\Drivers\\'.$this->getDriver().'\\Scheduler', [$this]);
41
        }
42
    }
43
44
    /**
45
     * Resolve a class based on the driver configuration
46
     *
47
     * @return \Indatus\Dispatcher\Scheduling\ScheduleService
48
     */
49 4
    public function resolveServiceClass()
50
    {
51
        try {
52 4
            return $this->container->make($this->getDriver().'\\ScheduleService');
53 4
        } catch (ReflectionException $e) {
54 4
            return $this->container->make('Indatus\Dispatcher\Drivers\\'.$this->getDriver().'\\ScheduleService');
55
        }
56
    }
57
58
    /**
59
     * Get the dispatcher driver class
60
     *
61
     * @return string
62
     */
63 11
    public function getDriver()
64
    {
65 11
        return ucfirst($this->config->get('dispatcher::driver'));
66
    }
67
}
68