Completed
Push — master ( 86adbf...92b61e )
by
unknown
02:54 queued 10s
created

ProjectRepository::setSingleBasicInfo()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 2
nop 1
1
<?php
2
/**
3
 * This file contains only the ProjectRepository class.
4
 */
5
6
namespace Xtools;
7
8
use Mediawiki\Api\MediawikiApi;
9
use Mediawiki\Api\SimpleRequest;
10
use Psr\Container\ContainerInterface;
11
12
/**
13
 * This class provides data to the Project class.
14
 */
15
class ProjectRepository extends Repository
16
{
17
    /** @var array Project's 'dbName', 'url' and 'lang'. */
18
    protected $basicInfo;
19
20
    /** @var string[] Basic metadata if XTools is in single-wiki mode. */
21
    protected $singleBasicInfo;
22
23
    /** @var array Full Project metadata, including $basicInfo. */
24
    protected $metadata;
25
26
    /** @var string The cache key for the 'all project' metadata. */
27
    protected $cacheKeyAllProjects = 'allprojects';
28
29
    /**
30
     * Convenience method to get a new Project object based on a given identification string.
31
     * @param string $projectIdent The domain name, database name, or URL of a project.
32
     * @param ContainerInterface $container Symfony's container.
33
     * @return Project
34
     */
35
    public static function getProject($projectIdent, ContainerInterface $container)
36
    {
37
        $project = new Project($projectIdent);
38
        $projectRepo = new ProjectRepository();
39
        $projectRepo->setContainer($container);
0 ignored issues
show
Compatibility introduced by
$container of type object<Psr\Container\ContainerInterface> is not a sub-type of object<Symfony\Component...ncyInjection\Container>. It seems like you assume a concrete implementation of the interface Psr\Container\ContainerInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
40
        if ($container->getParameter('app.single_wiki')) {
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Psr\Container\ContainerInterface as the method getParameter() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, LazyServiceProjectServiceContainer, ProjectServiceContainer, Symfony\Component\DependencyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...tainers\CustomContainer, Symfony\Component\Depend...ProjectServiceContainer, Symfony\Component\Depend...ProjectServiceContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
41
            $projectRepo->setSingleBasicInfo([
42
                'url' => $container->getParameter('wiki_url'),
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Psr\Container\ContainerInterface as the method getParameter() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, LazyServiceProjectServiceContainer, ProjectServiceContainer, Symfony\Component\DependencyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...tainers\CustomContainer, Symfony\Component\Depend...ProjectServiceContainer, Symfony\Component\Depend...ProjectServiceContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
43
                'dbName' => $container->getParameter('database_replica_name'),
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Psr\Container\ContainerInterface as the method getParameter() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, LazyServiceProjectServiceContainer, ProjectServiceContainer, Symfony\Component\DependencyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...tainers\CustomContainer, Symfony\Component\Depend...ProjectServiceContainer, Symfony\Component\Depend...ProjectServiceContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
44
            ]);
45
        }
46
        $project->setRepository($projectRepo);
47
        return $project;
48
    }
49
50
    /**
51
     * Get the XTools default project.
52
     * @param ContainerInterface $container
53
     * @return Project
54
     */
55
    public static function getDefaultProject(ContainerInterface $container)
56
    {
57
        $defaultProjectName = $container->getParameter('default_project');
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface Psr\Container\ContainerInterface as the method getParameter() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer, LazyServiceProjectServiceContainer, ProjectServiceContainer, Symfony\Component\DependencyInjection\Container, Symfony\Component\Depend...ection\ContainerBuilder, Symfony\Component\Depend...tainers\CustomContainer, Symfony\Component\Depend...ProjectServiceContainer, Symfony\Component\Depend...ProjectServiceContainer.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
58
        return self::getProject($defaultProjectName, $container);
59
    }
60
61
    /**
62
     * Get the global 'meta' project, which is either Meta (if this is Labs) or the default project.
63
     * @return Project
64
     */
65
    public function getGlobalProject()
66
    {
67
        if ($this->isLabs()) {
68
            return self::getProject('metawiki', $this->container);
69
        } else {
70
            return self::getDefaultProject($this->container);
71
        }
72
    }
73
74
    /**
75
     * For single-wiki installations, you must manually set the wiki URL and database name
76
     * (because there's no meta.wiki database to query).
77
     * @param $metadata
78
     * @throws \Exception
79
     */
80
    public function setSingleBasicInfo($metadata)
81
    {
82
        if (!array_key_exists('url', $metadata) || !array_key_exists('dbName', $metadata)) {
83
            $error = "Single-wiki metadata should contain 'url', 'dbName' and 'lang' keys.";
84
            throw new \Exception($error);
85
        }
86
        $this->singleBasicInfo = array_intersect_key($metadata, [
87
            'url' => '',
88
            'dbName' => '',
89
            'lang' => '',
90
        ]);
91
    }
92
93
    /**
94
     * Get the 'dbName', 'url' and 'lang' of all projects.
95
     * @return string[] Each item has 'dbName', 'url' and 'lang' keys.
96
     */
97
    public function getAll()
98
    {
99
        $this->log->debug(__METHOD__." Getting all projects' metadata");
100
        // Single wiki mode?
101
        if ($this->singleBasicInfo) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->singleBasicInfo of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
102
            return [$this->getOne('')];
0 ignored issues
show
Bug Best Practice introduced by
The return type of return array($this->getOne('')); (string[][]) is incompatible with the return type documented by Xtools\ProjectRepository::getAll of type string[].

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
103
        }
104
105
        // Maybe we've already fetched it.
106
        if ($this->cache->hasItem($this->cacheKeyAllProjects)) {
107
            return $this->cache->getItem($this->cacheKeyAllProjects)->get();
108
        }
109
110
        // Otherwise, fetch all from the database.
111
        $wikiQuery = $this->getMetaConnection()->createQueryBuilder();
112
        $wikiQuery->select(['dbname AS dbName', 'url', 'lang'])->from('wiki');
113
        $projects = $wikiQuery->execute()->fetchAll();
114
        $projectsMetadata = [];
115
        foreach ($projects as $project) {
116
            $projectsMetadata[$project['dbName']] = $project;
117
        }
118
119
        // Cache and return.
120
        $cacheItem = $this->cache->getItem($this->cacheKeyAllProjects);
121
        $cacheItem->set($projectsMetadata);
122
        $cacheItem->expiresAfter(new \DateInterval('P1D'));
123
        $this->cache->save($cacheItem);
124
        return $projectsMetadata;
125
    }
126
127
    /**
128
     * Get the 'dbName', 'url' and 'lang' of a project. This is all you need
129
     *   to make database queries. More comprehensive metadata can be fetched
130
     *   with getMetadata() at the expense of an API call.
131
     * @param string $project A project URL, domain name, or database name.
132
     * @return string[] With 'dbName', 'url' and 'lang' keys.
133
     */
134
    public function getOne($project)
135
    {
136
        $this->log->debug(__METHOD__." Getting metadata about $project");
137
        // For single-wiki setups, every project is the same.
138
        if ($this->singleBasicInfo) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->singleBasicInfo of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
139
            return $this->singleBasicInfo;
140
        }
141
142
        // For muli-wiki setups, first check the cache.
143
        // First the all-projects cache, then the individual one.
144
        if ($this->cache->hasItem($this->cacheKeyAllProjects)) {
145
            foreach ($this->cache->getItem($this->cacheKeyAllProjects)->get() as $projMetadata) {
146
                if ($projMetadata['dbName'] == "$project"
147
                    || $projMetadata['url'] == "$project"
148
                    || $projMetadata['url'] == "https://$project") {
149
                    $this->log->debug(__METHOD__ . " Using cached data for $project");
150
                    return $projMetadata;
151
                }
152
            }
153
        }
154
        $cacheKey = "project.$project";
155
        if ($this->cache->hasItem($cacheKey)) {
156
            return $this->cache->getItem($cacheKey)->get();
157
        }
158
159
        // Otherwise, fetch the project's metadata from the meta.wiki table.
160
        $wikiQuery = $this->getMetaConnection()->createQueryBuilder();
161
        $wikiQuery->select(['dbname AS dbName', 'url', 'lang'])
162
            ->from('wiki')
163
            ->where($wikiQuery->expr()->eq('dbname', ':project'))
164
            // The meta database will have the project's URL stored as https://en.wikipedia.org
165
            // so we need to query for it accordingly, trying different variations the user
166
            // might have inputted.
167
            ->orwhere($wikiQuery->expr()->like('url', ':projectUrl'))
168
            ->orwhere($wikiQuery->expr()
169
                ->like('url', ':projectUrl2'))
170
            ->setParameter('project', $project)
171
            ->setParameter('projectUrl', "https://$project")
172
            ->setParameter('projectUrl2', "https://$project.org");
173
        $wikiStatement = $wikiQuery->execute();
174
175
        // Fetch and cache the wiki data.
176
        $basicInfo = $wikiStatement->fetch();
177
178
        $cacheItem = $this->cache->getItem($cacheKey);
179
        $cacheItem->set($basicInfo)
180
            ->expiresAfter(new \DateInterval('PT1H'));
181
        $this->cache->save($cacheItem);
182
183
        return $basicInfo;
184
    }
185
186
    /**
187
     * Get metadata about a project, including the 'dbName', 'url' and 'lang'
188
     *
189
     * @param string $projectUrl The project's URL.
190
     * @return array With 'dbName', 'url', 'lang', 'general' and 'namespaces' keys.
191
     *   'general' contains: 'wikiName', 'articlePath', 'scriptPath', 'script',
192
     *   'timezone', and 'timezoneOffset'; 'namespaces' contains all namespace
193
     *   names, keyed by their IDs.
194
     */
195
    public function getMetadata($projectUrl)
196
    {
197
        // First try variable cache
198
        if ($this->metadata) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->metadata of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
199
            return $this->metadata;
200
        }
201
202
        // Redis cache
203
        $cacheKey = "projectMetadata." . preg_replace("/[^A-Za-z0-9]/", '', $projectUrl);
204 View Code Duplication
        if ($this->cache->hasItem($cacheKey)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
205
            $this->metadata = $this->cache->getItem($cacheKey)->get();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->cache->getItem($cacheKey)->get() of type * is incompatible with the declared type array of property $metadata.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
206
            return $this->metadata;
207
        }
208
209
        $api = MediawikiApi::newFromPage($projectUrl);
210
211
        $params = ['meta' => 'siteinfo', 'siprop' => 'general|namespaces'];
212
        $query = new SimpleRequest('query', $params);
213
214
        $this->metadata = [
215
            'general' => [],
216
            'namespaces' => [],
217
        ];
218
219
        // Even if general info could not be fetched,
220
        //   return dbName, url and lang if already known
221
        if ($this->basicInfo) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->basicInfo of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
222
            $this->metadata['dbName'] = $this->basicInfo['dbName'];
223
            $this->metadata['url'] = $this->basicInfo['url'];
224
            $this->metadata['lang'] = $this->basicInfo['lang'];
225
        }
226
227
        $res = $api->getRequest($query);
228
229
        if (isset($res['query']['general'])) {
230
            $info = $res['query']['general'];
231
232
            $this->metadata['dbName'] = $info['wikiid'];
233
            $this->metadata['url'] = $info['server'];
234
            $this->metadata['lang'] = $info['lang'];
235
236
            $this->metadata['general'] = [
237
                'wikiName' => $info['sitename'],
238
                'articlePath' => $info['articlepath'],
239
                'scriptPath' => $info['scriptpath'],
240
                'script' => $info['script'],
241
                'timezone' => $info['timezone'],
242
                'timeOffset' => $info['timeoffset'],
243
            ];
244
        }
245
246
        if (isset($res['query']['namespaces'])) {
247
            foreach ($res['query']['namespaces'] as $namespace) {
248
                if ($namespace['id'] < 0) {
249
                    continue;
250
                }
251
252
                if (isset($namespace['name'])) {
253
                    $name = $namespace['name'];
254
                } elseif (isset($namespace['*'])) {
255
                    $name = $namespace['*'];
256
                } else {
257
                    continue;
258
                }
259
260
                $this->metadata['namespaces'][$namespace['id']] = $name;
261
            }
262
        }
263
264
        $cacheItem = $this->cache->getItem($cacheKey);
265
        $cacheItem->set($this->metadata)
266
            ->expiresAfter(new \DateInterval('PT1H'));
267
        $this->cache->save($cacheItem);
268
269
        return $this->metadata;
270
    }
271
272
    /**
273
     * Get a list of projects that have opted in to having all their users' restricted statistics
274
     * available to anyone.
275
     *
276
     * @return string[]
277
     */
278
    public function optedIn()
279
    {
280
        $optedIn = $this->container->getParameter('opted_in');
281
        // In case there's just one given.
282
        if (!is_array($optedIn)) {
283
            $optedIn = [ $optedIn ];
284
        }
285
        return $optedIn;
286
    }
287
288
    /**
289
     * The path to api.php
290
     *
291
     * @return string
292
     */
293
    public function getApiPath()
294
    {
295
        return $this->container->getParameter('api_path');
296
    }
297
298
    /**
299
     * Get a page from the given Project.
300
     * @param Project $project The project.
301
     * @param string $pageName The name of the page.
302
     * @return Page
303
     */
304
    public function getPage(Project $project, $pageName)
305
    {
306
        $pageRepo = new PagesRepository();
307
        $pageRepo->setContainer($this->container);
308
        $page = new Page($project, $pageName);
309
        $page->setRepository($pageRepo);
310
        return $page;
311
    }
312
313
    /**
314
     * Check to see if a page exists on this project and has some content.
315
     * @param Project $project The project.
316
     * @param int $namespaceId The page namespace ID.
317
     * @param string $pageTitle The page title, without namespace.
318
     * @return bool
319
     */
320
    public function pageHasContent(Project $project, $namespaceId, $pageTitle)
321
    {
322
        $conn = $this->getProjectsConnection();
323
        $pageTable = $this->getTableName($project->getDatabaseName(), 'page');
324
        $query = "SELECT page_id "
325
             . " FROM $pageTable "
326
             . " WHERE page_namespace = :ns AND page_title = :title AND page_len > 0 "
327
             . " LIMIT 1";
328
        $params = [
329
            'ns' => $namespaceId,
330
            'title' => $pageTitle,
331
        ];
332
        $pages = $conn->executeQuery($query, $params)->fetchAll();
333
        return count($pages) > 0;
334
    }
335
336
    /**
337
     * Get page assessments configuration for this project
338
     *   and cache in static variable.
339
     * @param string $projectDomain The project domain such as en.wikipedia.org
340
     * @return string[]|bool As defined in config/assessments.yml,
341
     *                       or false if none exists
342
     */
343
    public function getAssessmentsConfig($projectDomain)
344
    {
345
        static $assessmentsConfig = null;
346
        if ($assessmentsConfig !== null) {
347
            return $assessmentsConfig;
348
        }
349
350
        $projectsConfig = $this->container->getParameter('assessments');
351
352
        if (isset($projectsConfig[$projectDomain])) {
353
            $assessmentsConfig = $projectsConfig[$projectDomain];
354
        } else {
355
            $assessmentsConfig = false;
356
        }
357
358
        return $assessmentsConfig;
359
    }
360
}
361