1 | <?php |
||
26 | class ProfilesController extends Controller |
||
27 | { |
||
28 | /** |
||
29 | * Renders profiles page. |
||
30 | * |
||
31 | * @return Response |
||
32 | */ |
||
33 | public function listAction() |
||
37 | |||
38 | /** |
||
39 | * Returns a json list of profiles |
||
40 | * |
||
41 | * @return JsonResponse |
||
42 | */ |
||
43 | public function getAllProfilesAction() |
||
44 | { |
||
45 | $profiles = []; |
||
46 | /** @var Repository $repo */ |
||
47 | $repo = $this->get($this->getParameter('ongr_settings.repo')); |
||
48 | |||
49 | $search = $repo->createSearch(); |
||
50 | $search->addAggregation(new TermsAggregation('profiles', 'profile')); |
||
51 | |||
52 | /** @var DocumentIterator $result */ |
||
53 | $result = $repo->findDocuments($search); |
||
54 | |||
55 | /** @var AggregationValue $agg */ |
||
56 | foreach ($result->getAggregation('profiles') as $agg) { |
||
|
|||
57 | $profiles[] = $agg->getValue('key'); |
||
58 | } |
||
59 | |||
60 | if (empty($profiles) || !in_array('default', $profiles)) { |
||
61 | array_unshift($profiles, 'default'); |
||
62 | } |
||
63 | |||
64 | return new JsonResponse($profiles); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Returns a json list of profiles |
||
69 | * |
||
70 | * @return JsonResponse |
||
71 | */ |
||
72 | public function getFullProfilesAction() |
||
80 | |||
81 | /** |
||
82 | * Toggle profile activation. |
||
83 | * |
||
84 | * @param Request $request |
||
85 | * |
||
86 | * @return JsonResponse |
||
87 | */ |
||
88 | public function toggleProfileAction(Request $request) |
||
122 | } |
||
123 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.