Passed
Push — master ( cf7cac...e5693c )
by Michel
01:22
created

SyncOptionsFactory   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 11
eloc 13
dl 0
loc 26
ccs 12
cts 13
cp 0.9231
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 21 11
1
<?php
2
declare(strict_types=1);
3
4
namespace TogglJira\Options;
5
6
use Interop\Container\ContainerInterface;
7
use Zend\Config\Reader\Json;
8
use Zend\ServiceManager\Factory\FactoryInterface;
9
10
class SyncOptionsFactory implements FactoryInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 1
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null): SyncOptions
16
    {
17 1
        $reader = new Json();
18 1
        $config = $reader->fromFile(__DIR__ . '/../../../../config.json');
19
20 1
        if ((!isset($config['jiraUsername']) || empty($config['jiraUsername'])) ||
21 1
        (!isset($config['jiraPassword']) || empty($config['jiraPassword'])) ||
22 1
        (!isset($config['togglApiKey']) || empty($config['togglApiKey'])) ||
23 1
        (!isset($config['jiraUrl']) || empty($config['jiraUrl']))
24
        ) {
25
            throw new \RuntimeException('Invalid config.json, please fill out everything except lastSync');
26
        }
27
28 1
        if (isset($config['lastSync']['date']) && isset($config['lastSync']['timezone'])) {
29 1
            $config['lastSync'] = new \DateTimeImmutable(
30 1
                $config['lastSync']['date'],
31 1
                new \DateTimeZone($config['lastSync']['timezone'])
32
            );
33
        }
34
35 1
        return new SyncOptions($config);
36
    }
37
}
38