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.

BaseController::getDisplayOptions()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 17
rs 9.4285
c 2
b 0
f 0
cc 3
eloc 11
nc 4
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: wechsler
5
 * Date: 29/01/2017
6
 * Time: 12:43
7
 */
8
9
namespace Phase\TakeATicketBundle\Controller;
10
11
use Phase\TakeATicket\DataSource\AbstractSql;
12
use Phase\TakeATicket\Model\Instrument;
13
use Phase\TakeATicket\Model\Platform;
14
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
15
use Phase\TakeATicket\DataSource\Factory;
16
17
/**
18
 * @property  \Symfony\Component\DependencyInjection\Container container
19
 */
20
abstract class BaseController extends Controller
21
{
22
    /**
23
     * Use getDataStore() rather than accessing directly as this may not be populated
24
     *
25
     * @var AbstractSql
26
     */
27
    protected $dataSource;
28
29
    /**
30
     * @return AbstractSql
31
     */
32
    protected function getDataStore()
33
    {
34
        if (!$this->dataSource) {
35
            $this->dataSource = Factory::datasourceFromDbConnection($this->get('database_connection'));
36
            $this->dataSource->setUpcomingCount($this->getUpcomingCount()); // FIXME reduce navel-gazing
37
        }
38
        return $this->dataSource;
39
    }
40
41
    /**
42
     * Get public-safe display options from config, with overrides if possible
43
     *
44
     * @return array
45
     */
46
    protected function getDisplayOptions()
47
    {
48
        $displayOptions = $this->container->hasParameter('displayOptions') ?
49
            $this->getParameter('displayOptions') : [];
50
51
        $displayOptions['upcomingCount'] = $this->getUpcomingCount();
52
        $displayOptions['songInPreview'] = (bool)$this->getDataStore()->fetchSetting('songInPreview');
53
        $displayOptions['selfSubmission'] = (bool)$this->getDataStore()->fetchSetting('selfSubmission');
54
        $displayOptions['selfSubmissionKeyNeeded'] = (bool)$this->getDataStore()->fetchSetting('selfSubmissionKey');
55
56
        if ($this->isGranted('ROLE_ADMIN')) {
57
            $displayOptions['songInPreview'] = true; // force for logged-in users
58
            $displayOptions['isAdmin'] = true; // force for logged-in users
59
        }
60
61
        return $displayOptions;
62
    }
63
64
    /**
65
     * @return int
66
     */
67
    protected function getUpcomingCount()
68
    {
69
        return $this->getDataStore()->fetchSetting('upcomingCount') ?: 3;
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    protected function defaultViewParams()
76
    {
77
        $allPlatforms = $this->getDataStore()->fetchAllPlatforms();
78
        $platformNames = array_map(function (Platform $platform) {
79
            return $platform->getName();
80
        }, $allPlatforms);
81
82
        $instruments = $this->getDataStore()->fetchAllInstruments();
83
        $instrumentOrder = array_map(function (Instrument $instrument) {
84
            return $instrument->getAbbreviation();
85
        }, $instruments);
86
87
        /** @noinspection RealpathInSteamContextInspection */
88
        $viewParams = [
89
            'base_dir' => realpath($this->getParameter('kernel.root_dir') . '/..'),
90
            'allPlatforms' => $platformNames,
91
            'instrumentOrder' => $instrumentOrder,
92
        ];
93
        $viewParams['displayOptions'] = $this->getDisplayOptions();
94
95
        return $viewParams;
96
    }
97
}
98