Skip to content

Commit 25f3748

Browse files
committed
PHP: docstring and lint Repository
1 parent f61ab57 commit 25f3748

File tree

2 files changed

+61
-17
lines changed

2 files changed

+61
-17
lines changed

lizmap/modules/lizmap/lib/Project/Repository.php

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
class Repository
1919
{
2020
/**
21-
* services properties.
21+
* Repository properties.
22+
*
23+
* @var string[]
2224
*/
2325
private static $properties = array(
2426
'label',
@@ -28,7 +30,11 @@ class Repository
2830
);
2931

3032
/**
31-
* services properties options.
33+
* Repository properties options.
34+
*
35+
* @var array<string, array<string, bool|string>>
36+
*
37+
* @phpstan-var array<string, array{fieldType: string, required: bool}>
3238
*/
3339
private static $propertiesOptions = array(
3440
'label' => array(
@@ -51,26 +57,38 @@ class Repository
5157

5258
/**
5359
* Lizmap repository key.
60+
*
61+
* @var string
5462
*/
5563
private $key = '';
5664

5765
/**
5866
* Lizmap repository configuration data.
67+
*
68+
* @var array
5969
*/
6070
private $data = array();
6171

6272
/**
63-
* @var Project[] list of projects. keys are projects names
73+
* @var array<string, Project> list of projects instances. keys are projects names
6474
*/
6575
protected $projectInstances = array();
6676

6777
/**
6878
* The configuration files folder path.
79+
*
80+
* @var string
6981
*/
7082
private $varPath = '';
7183

84+
/**
85+
* @var \lizmapServices
86+
*/
7287
protected $services;
7388

89+
/**
90+
* @var AppContextInterface
91+
*/
7492
protected $appContext;
7593

7694
/**
@@ -103,7 +121,7 @@ public function __construct($key, $data, $varPath, $services, $appContext)
103121
/**
104122
* @return string the technical name of the repository
105123
*/
106-
public function getKey()
124+
public function getKey(): string
107125
{
108126
return $this->key;
109127
}
@@ -113,7 +131,7 @@ public function getKey()
113131
*
114132
* @return string the repository label
115133
*/
116-
public function getLabel()
134+
public function getLabel(): string
117135
{
118136
return $this->getData('label');
119137
}
@@ -123,7 +141,7 @@ public function getLabel()
123141
*
124142
* @return bool true if it is allowed
125143
*/
126-
public function allowUserDefinedThemes()
144+
public function allowUserDefinedThemes(): bool
127145
{
128146
$value = $this->getData('allowUserDefinedThemes');
129147
if (empty($value)) {
@@ -147,7 +165,7 @@ public function allowUserDefinedThemes()
147165
*
148166
* @return string the value of the ACAO header. If empty, the header should not be set.
149167
*/
150-
public function getACAOHeaderValue($referer)
168+
public function getACAOHeaderValue($referer): string
151169
{
152170
$origins = $this->getData('accessControlAllowOrigin');
153171
if (!$origins || $referer == '') {
@@ -173,6 +191,9 @@ public function getACAOHeaderValue($referer)
173191
return '';
174192
}
175193

194+
/**
195+
* @var null|string the cleaned path of the repository, with a trailing slash
196+
*/
176197
protected $cleanedPath;
177198

178199
/**
@@ -210,27 +231,48 @@ public function getPath()
210231
return $this->cleanedPath;
211232
}
212233

213-
public function getOriginalPath()
234+
/**
235+
* Get the original path.
236+
*/
237+
public function getOriginalPath(): string
214238
{
215239
return $this->data['path'];
216240
}
217241

242+
/**
243+
* Check if the repository has a valid path.
244+
*/
218245
public function hasValidPath(): bool
219246
{
220247
return $this->getPath() !== false;
221248
}
222249

223-
public static function getProperties()
250+
/**
251+
* Get the list of properties of a repository.
252+
*
253+
* @return string[]
254+
*/
255+
public static function getProperties(): array
224256
{
225257
return self::$properties;
226258
}
227259

228-
public static function getRepoProperties()
260+
/**
261+
* Get theR repository properties options.
262+
*
263+
* @return array<string, array{fieldType: string, required: bool}>
264+
*/
265+
public static function getRepoProperties(): array
229266
{
230267
return self::$propertiesOptions;
231268
}
232269

233-
public static function getPropertiesOptions()
270+
/**
271+
* Get theR repository properties options.
272+
*
273+
* @return array<string, array{fieldType: string, required: bool}>
274+
*/
275+
public static function getPropertiesOptions(): array
234276
{
235277
return self::$propertiesOptions;
236278
}
@@ -259,7 +301,7 @@ public function getData($key)
259301
*
260302
* @return bool true if there is at least one valid data in $data
261303
*/
262-
public function update($data, $ini)
304+
public function update($data, $ini): bool
263305
{
264306
// Set section
265307
$section = 'repository:'.$this->key;
@@ -291,6 +333,8 @@ public function update($data, $ini)
291333
* @param bool $keepReference if we need to keep reference in the repository property projectInstances
292334
*
293335
* @return null|Project null if it does not exist
336+
*
337+
* @throws UnknownLizmapProjectException if the project does not exist
294338
*/
295339
public function getProject($key, $keepReference = true)
296340
{
@@ -320,7 +364,7 @@ public function getProject($key, $keepReference = true)
320364
*
321365
* @return Project[]
322366
*/
323-
public function getProjects()
367+
public function getProjects(): array
324368
{
325369
$projects = array();
326370
$dir = $this->getPath();
@@ -370,7 +414,7 @@ public function getProjects()
370414
*
371415
* @return ProjectMetadata[]
372416
*/
373-
public function getProjectsMetadata($checkAcl = true)
417+
public function getProjectsMetadata($checkAcl = true): array
374418
{
375419
$data = array();
376420
$dir = $this->getPath();
@@ -422,7 +466,7 @@ public function getProjectsMetadata($checkAcl = true)
422466
*
423467
* @return ProjectMainData[]
424468
*/
425-
public function getProjectsMainData()
469+
public function getProjectsMainData(): array
426470
{
427471
$data = array();
428472
$dir = $this->getPath();

tests/units/classes/Project/ProjectTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function testGetRelativeQgisPath($relative, $root, $file, $expectedPath):
9393
null
9494
);
9595
$proj = new ProjectForTests();
96-
$proj->setRepo(new Project\Repository(null, array('path' => ''), null, null, null));
96+
$proj->setRepo(new Project\Repository('key', array('path' => ''), null, null, null));
9797
$proj->setServices($services);
9898
$proj->setFile($file, 0, 0);
9999
$path = $proj->getRelativeQgisPath();
@@ -213,7 +213,7 @@ public function testHasEditionLayers($editionLayers, $acl, $unset, $expectedRet)
213213
$eLayers->{$key} = clone $obj;
214214
}
215215
$config = new Project\ProjectConfig((object) array('editionLayers' => $eLayers));
216-
$rep = new Project\Repository(null, array(), null, null, null);
216+
$rep = new Project\Repository('key', array(), null, null, null);
217217
$context = new ContextForTests();
218218
$context->setResult($acl);
219219
$proj = new ProjectForTests($context);

0 commit comments

Comments
 (0)