GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b10e46...20af00 )
by Christian
263:11
created

SitemapServiceManager::getServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * (c) Christian Gripp <[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
namespace Core23\SitemapBundle\Sitemap;
13
14
use Core23\SitemapBundle\Definition\SitemapDefinitionInterface;
15
use Core23\SitemapBundle\Exception\SitemapNotFoundException;
16
use Symfony\Component\OptionsResolver\OptionsResolver;
17
18
final class SitemapServiceManager implements SitemapServiceManagerInterface
19
{
20
    /**
21
     * @var SitemapServiceInterface[]
22
     */
23
    private $services;
24
25
    /**
26
     * @param SitemapServiceInterface[] $services
27
     */
28
    public function __construct(array $services = [])
29
    {
30
        $this->services = [];
31
32
        foreach ($services as $id => $service) {
33
            $this->addSitemap($id, $service);
34
        }
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function get(SitemapDefinitionInterface $definition): ?SitemapServiceInterface
41
    {
42
        $service = $this->getService($definition->getType());
43
44
        $optionsResolver = new OptionsResolver();
45
        $this->configureSettings($optionsResolver, $service);
46
47
        $settings = $optionsResolver->resolve($definition->getSettings());
48
        $definition->setSettings($settings);
49
50
        return $service;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function addSitemap(string $id, SitemapServiceInterface $service): void
57
    {
58
        $this->services[$id] = $service;
59
    }
60
61
    /**
62
     * @param string $id
63
     *
64
     * @return bool
65
     */
66
    private function has(string $id): bool
67
    {
68
        return isset($this->services[$id]) ? true : false;
69
    }
70
71
    /**
72
     * @param string $id
73
     *
74
     * @return SitemapServiceInterface
75
     */
76
    private function getService(string $id): SitemapServiceInterface
77
    {
78
        if (!$this->has($id)) {
79
            throw new SitemapNotFoundException(sprintf('The sitemap service `%s` does not exist', $id));
80
        }
81
82
        return $this->services[$id];
83
    }
84
85
    /**
86
     * @param OptionsResolver         $resolver
87
     * @param SitemapServiceInterface $sitemap
88
     */
89
    private function configureSettings(OptionsResolver $resolver, SitemapServiceInterface $sitemap): void
90
    {
91
        $resolver
92
            ->setDefaults([
93
                'use_cache'        => true,
94
                'extra_cache_keys' => [],
95
                'ttl'              => 86400,
96
            ])
97
            ->setAllowedTypes('use_cache', 'bool')
98
            ->setAllowedTypes('extra_cache_keys', 'array')
99
            ->setAllowedTypes('ttl', 'int')
100
        ;
101
102
        $sitemap->configureSettings($resolver);
103
    }
104
}
105