Failed Conditions
Push — master ( 4f9353...7eeb29 )
by Michel
02:37
created

SyncOptionsFactory   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

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