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 ( 35aa2b...d96a39 )
by
unknown
31:28 queued 13:57
created

CmisBindingFactory::addDefaultSessionParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
ccs 2
cts 2
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 1
crap 1
1
<?php
2
namespace Dkd\PhpCmis\Bindings;
3
4
/**
5
 * This file is part of php-cmis-lib.
6
 *
7
 * (c) Sascha Egerer <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
use Dkd\PhpCmis\Bindings\Browser\CmisBrowserBinding;
14
use Dkd\PhpCmis\Converter\JsonConverter;
15
use Dkd\PhpCmis\Exception\CmisInvalidArgumentException;
16
use Dkd\PhpCmis\SessionParameter;
17
use Doctrine\Common\Cache\ArrayCache;
18
use Doctrine\Common\Cache\Cache;
19
use GuzzleHttp\Client;
20
21
/**
22
 * Default factory for a CMIS binding instance.
23
 */
24
class CmisBindingFactory
25
{
26
    /**
27
     * Create a browser binding
28
     *
29
     * @param array $sessionParameters
30
     * @param Cache|null $typeDefinitionCache
31
     * @return CmisBinding
32
     */
33 2
    public function createCmisBrowserBinding(array $sessionParameters, Cache $typeDefinitionCache = null)
34
    {
35
        $this->validateCmisBrowserBindingParameters($sessionParameters);
36
37 2
        return new CmisBinding(new Session(), $sessionParameters, $typeDefinitionCache);
38
    }
39 1
40
    protected function validateCmisBrowserBindingParameters(array &$sessionParameters)
41
    {
42 5
        $sessionParameters[SessionParameter::BINDING_CLASS] = $sessionParameters[SessionParameter::BINDING_CLASS] ?? CmisBrowserBinding::class;
43
        $sessionParameters[SessionParameter::BROWSER_SUCCINCT] = $sessionParameters[SessionParameter::BROWSER_SUCCINCT] ?? true;
44 5
        $this->addDefaultSessionParameters($sessionParameters);
45 5
        $this->check($sessionParameters, SessionParameter::BROWSER_URL);
46 5
    }
47 5
48 5
    /**
49 5
     * Sets some parameters to a default value if they are not already set
50 5
     *
51 5
     * @param array $sessionParameters
52 3
     */
53
    protected function addDefaultSessionParameters(array &$sessionParameters)
54
    {
55
        $sessionParameters[SessionParameter::CACHE_SIZE_REPOSITORIES] = $sessionParameters[SessionParameter::CACHE_SIZE_REPOSITORIES] ?? 10;
56
        $sessionParameters[SessionParameter::CACHE_SIZE_TYPES] = $sessionParameters[SessionParameter::CACHE_SIZE_TYPES] ?? 100;
57
        $sessionParameters[SessionParameter::CACHE_SIZE_LINKS] = $sessionParameters[SessionParameter::CACHE_SIZE_LINKS] ?? 400;
58
        $sessionParameters[SessionParameter::HTTP_INVOKER_CLASS] = $sessionParameters[SessionParameter::HTTP_INVOKER_CLASS] ?? Client::class;
59 5
        $sessionParameters[SessionParameter::JSON_CONVERTER_CLASS] = $sessionParameters[SessionParameter::JSON_CONVERTER_CLASS] ?? JsonConverter::class;
60
        $sessionParameters[SessionParameter::TYPE_DEFINITION_CACHE_CLASS] = $sessionParameters[SessionParameter::TYPE_DEFINITION_CACHE_CLASS] ?? ArrayCache::class;
61 5
    }
62 5
63 5
    /**
64 5
     * Checks if the given parameter is present. If not, throw an
65 5
     * <code>IllegalArgumentException</code>.
66 5
     *
67 5
     * @param array $sessionParameters
68 5
     * @param string $parameter
69 5
     * @throws CmisInvalidArgumentException
70 5
     * @return boolean
71 5
     */
72 5
    protected function check(array $sessionParameters, $parameter)
73 5
    {
74 5
        if (empty($sessionParameters[$parameter])) {
75 5
            throw new CmisInvalidArgumentException(sprintf('Parameter "%s" is missing!', $parameter));
76 5
        }
77 5
78 5
        return true;
79 5
    }
80
}
81