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.

RepositoryService::getRepositoryInfo()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
1
<?php
2
namespace Dkd\PhpCmis\Bindings\Browser;
3
4
/*
5
 * This file is part of php-cmis-client.
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\Constants;
14
use Dkd\PhpCmis\Data\ExtensionDataInterface;
15
use Dkd\PhpCmis\Data\RepositoryInfoInterface;
16
use Dkd\PhpCmis\Definitions\TypeDefinitionContainerInterface;
17
use Dkd\PhpCmis\Definitions\TypeDefinitionInterface;
18
use Dkd\PhpCmis\Definitions\TypeDefinitionListInterface;
19
use Dkd\PhpCmis\Exception\CmisObjectNotFoundException;
20
use Dkd\PhpCmis\RepositoryServiceInterface;
21
22
/**
23
 * Repository Service Browser Binding client.
24
 */
25
class RepositoryService extends AbstractBrowserBindingService implements RepositoryServiceInterface
26
{
27
    /**
28
     * Creates a new type.
29
     *
30
     * @param string $repositoryId The identifier for the repository.
31
     * @param TypeDefinitionInterface $type A fully populated type definition including all new property definitions.
32
     * @param ExtensionDataInterface|null $extension
33
     * @return TypeDefinitionInterface
34
     */
35 1 View Code Duplication
    public function createType($repositoryId, TypeDefinitionInterface $type, ExtensionDataInterface $extension = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
    {
37 1
        $url = $this->getRepositoryUrl($repositoryId);
38
39 1
        $url->getQuery()->modify(
40
            [
41 1
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_CREATE_TYPE,
42 1
                Constants::CONTROL_TYPE => $this->getJsonConverter()->convertFromTypeDefinition($type)
43 1
            ]
44 1
        );
45
46 1
        return $this->getJsonConverter()->convertTypeDefinition($this->postJson($url));
47
    }
48 1
49
    /**
50
     * Deletes a type.
51
     *
52
     * @param string $repositoryId The identifier for the repository.
53
     * @param string $typeId The typeId of an object-type specified in the repository.
54
     * @param ExtensionDataInterface|null $extension
55
     */
56
    public function deleteType($repositoryId, $typeId, ExtensionDataInterface $extension = null)
57
    {
58 1
        $url = $this->getRepositoryUrl($repositoryId);
59
60 1
        $url->getQuery()->modify(
61
            [
62 1
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_DELETE_TYPE,
63
                Constants::CONTROL_TYPE_ID => $typeId
64 1
            ]
65 1
        );
66 1
67 1
        $this->post($url);
68
    }
69 1
70 1
    /**
71
     * Returns information about the CMIS repository, the optional capabilities it
72
     * supports and its access control information if applicable.
73
     *
74
     * @param string $repositoryId The identifier for the repository.
75
     * @param ExtensionDataInterface|null $extension
76
     * @throws CmisObjectNotFoundException
77
     * @return RepositoryInfoInterface
78
     */
79
    public function getRepositoryInfo($repositoryId, ExtensionDataInterface $extension = null)
80
    {
81 2
        foreach ($this->getRepositoriesInternal($repositoryId) as $repositoryInfo) {
82
            if ($repositoryInfo->getId() === $repositoryId) {
83 2
                return $repositoryInfo;
84 2
            }
85 1
        }
86
87 2
        throw new CmisObjectNotFoundException(sprintf('Repository "%s" not found!', $repositoryId));
88
    }
89 1
90
    /**
91
     * Returns a list of CMIS repository information available from this CMIS service endpoint.
92
     * In contrast to the CMIS specification this method returns repository infos not only repository ids.
93
     *
94
     * @param ExtensionDataInterface|null $extension
95
     * @return RepositoryInfoInterface[]
96
     */
97
    public function getRepositoryInfos(ExtensionDataInterface $extension = null)
98
    {
99 1
        return $this->getRepositoriesInternal();
100
    }
101 1
102
    /**
103
     * Returns the list of object types defined for the repository that are children of the specified type.
104
     *
105
     * @param string $repositoryId the identifier for the repository
106
     * @param string|null $typeId the typeId of an object type specified in the repository
107
     *      (if not specified the repository MUST return all base object types)
108
     * @param boolean $includePropertyDefinitions if <code>true</code> the repository MUST return the property
109
     *      definitions for each object type returned (default is <code>false</code>)
110
     * @param integer|null $maxItems the maximum number of items to return in a response
111
     *      (default is repository specific)
112
     * @param integer $skipCount number of potential results that the repository MUST skip/page over before
113
     *      returning any results (default is 0)
114
     * @param ExtensionDataInterface|null $extension
115
     * @return TypeDefinitionListInterface
116
     */
117 View Code Duplication
    public function getTypeChildren(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
118
        $repositoryId,
119
        $typeId = null,
120
        $includePropertyDefinitions = false,
121
        $maxItems = null,
122
        $skipCount = 0,
123
        ExtensionDataInterface $extension = null
124
    ) {
125
        $url = $this->getRepositoryUrl($repositoryId, Constants::SELECTOR_TYPE_CHILDREN);
126
        $url->getQuery()->modify(
127
            [
128
                Constants::PARAM_PROPERTY_DEFINITIONS => $includePropertyDefinitions ? 'true' : 'false',
129
                Constants::PARAM_SKIP_COUNT => $skipCount,
130
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
131
            ]
132
        );
133
134
        if ($typeId !== null) {
135
            $url->getQuery()->modify([Constants::PARAM_TYPE_ID => $typeId]);
136
        }
137
138
        if ($maxItems !== null) {
139
            $url->getQuery()->modify([Constants::PARAM_MAX_ITEMS => $maxItems]);
140
        }
141
142
        $responseData = (array) $this->readJson($url);
143
144
        return $this->getJsonConverter()->convertTypeChildren($responseData);
145
    }
146
147
    /**
148
     * Gets the definition of the specified object type.
149
     *
150
     * @param string $repositoryId the identifier for the repository
151
     * @param string $typeId he type definition
152
     * @param ExtensionDataInterface|null $extension
153
     * @param boolean $useCache
154
     * @return TypeDefinitionInterface|null the newly created type
155
     */
156
    public function getTypeDefinition(
157
        $repositoryId,
158 1
        $typeId,
159
        ExtensionDataInterface $extension = null,
160
        $useCache = true
161
    ) {
162
        $cache = null;
163
        $cacheKey = $repositoryId . '-' . $typeId;
164 1
165 1
        // if the cache should be used and the extension is not set, check the cache first
166
        if ($useCache === true && empty($extension)) {
167
            $cache = $this->cmisBindingsHelper->getTypeDefinitionCache($this->getSession());
168 1
169 1
            if ($cache->contains($cacheKey)) {
170
                return $cache->fetch($cacheKey);
171 1
            }
172
        }
173
        $typeDefinition = $this->getTypeDefinitionInternal($repositoryId, $typeId);
174 1
175 1
        if ($useCache === true && empty($extension)) {
176
            $cache->save($cacheKey, $typeDefinition);
177 1
        }
178 1
179 1
        return $typeDefinition;
180
    }
181 1
182
    /**
183
     * Returns the set of descendant object type defined for the repository under the specified type.
184
     *
185
     * @param string $repositoryId repositoryId - the identifier for the repository
186
     * @param string|null $typeId the typeId of an object type specified in the repository
187
     * (if not specified the repository MUST return all types and MUST ignore the value of the depth parameter)
188
     * @param integer|null $depth the number of levels of depth in the type hierarchy from which
189
     * to return results (default is repository specific)
190
     * @param boolean $includePropertyDefinitions if <code>true</code> the repository MUST return the property
191
     * definitions for each object type returned (default is <code>false</code>)
192
     * @param ExtensionDataInterface|null $extension
193
     * @return TypeDefinitionContainerInterface[]
194
     */
195 View Code Duplication
    public function getTypeDescendants(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
196
        $repositoryId,
197
        $typeId = null,
198
        $depth = null,
199
        $includePropertyDefinitions = false,
200
        ExtensionDataInterface $extension = null
201
    ) {
202
        $url = $this->getRepositoryUrl($repositoryId, Constants::SELECTOR_TYPE_DESCENDANTS);
203
        $url->getQuery()->modify(
204
            [
205
                Constants::PARAM_PROPERTY_DEFINITIONS => $includePropertyDefinitions ? 'true' : 'false',
206
                Constants::PARAM_DATETIME_FORMAT => (string) $this->getDateTimeFormat()
207
            ]
208
        );
209
210
        if ($typeId !== null) {
211
            $url->getQuery()->modify([Constants::PARAM_TYPE_ID => $typeId]);
212
        }
213
214
        if ($depth !== null) {
215
            $url->getQuery()->modify([Constants::PARAM_DEPTH => $depth]);
216
        }
217
218
        $responseData = (array) $this->readJson($url);
219
220
        return $this->getJsonConverter()->convertTypeDescendants($responseData);
221
    }
222
223
    /**
224
     * Updates a type.
225
     *
226
     * @param string $repositoryId the identifier for the repository
227
     * @param TypeDefinitionInterface $type the type definition
228
     * @param ExtensionDataInterface|null $extension
229
     * @return TypeDefinitionInterface the updated type
230
     */
231 View Code Duplication
    public function updateType($repositoryId, TypeDefinitionInterface $type, ExtensionDataInterface $extension = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
232
    {
233 1
        $url = $this->getRepositoryUrl($repositoryId);
234
235 1
        $url->getQuery()->modify(
236
            [
237 1
                Constants::CONTROL_CMISACTION => Constants::CMISACTION_UPDATE_TYPE,
238
                Constants::CONTROL_TYPE => json_encode($this->getJsonConverter()->convertFromTypeDefinition($type))
239 1
            ]
240 1
        );
241 1
242 1
        return $this->getJsonConverter()->convertTypeDefinition($this->postJson($url));
243
    }
244
}
245