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.
Completed
Push — master ( 50e57a...1d39d2 )
by Florian
03:06
created

FacetChoiceLoader::addFacets()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Stinger Entity Search package.
5
 *
6
 * (c) Oliver Kotte <[email protected]>
7
 * (c) Florian Meyer <[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
namespace StingerSoft\EntitySearchBundle\Form;
13
14
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
15
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
16
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
17
18
class FacetChoiceLoader implements ChoiceLoaderInterface {
19
20
	/** @var ChoiceListInterface */
21
	private $choiceList;
22
23
	private $facets;
24
25
	public function __construct(array $facets) {
26
		$this->facets = $facets;
27
	}
28
29
	public function addFacets($facets) {
30
		$this->facets = array_merge($this->facets, $facets);
31
	}
32
33
	/**
34
	 *
35
	 * {@inheritDoc}
36
	 *
37
	 * @see \Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::loadValuesForChoices()
38
	 */
39 View Code Duplication
	public function loadValuesForChoices(array $choices, $value = 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...
40
		// is called on form creat with $choices containing the preset of the bound entity
41
		$values = array();
42
		foreach($choices as $key => $choice) {
43
			// we use a DataTransformer, thus only plain values arrive as choices which can be used directly as value
44
			if(is_callable($value)) {
45
				$values[$key] = (string)call_user_func($value, $choice, $key);
46
			} else {
47
				$values[$key] = $choice;
48
			}
49
		}
50
		
51
		// this has to be done by yourself: array( label => value )
52
		// $labeledValues = MyLabelService::getLabels($values);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
53
		
54
		// // create internal choice list from loaded values
55
		// $this->choiceList = new ArrayChoiceList($labeledValues, $value);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
56
		
57
		return $values;
58
	}
59
60
	/**
61
	 *
62
	 * {@inheritDoc}
63
	 *
64
	 * @see \Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::loadChoiceList()
65
	 */
66
	public function loadChoiceList($value = null) {
67
		// is called on form view create after loadValuesForChoices of form create
68
		// if($this->choiceList instanceof ChoiceListInterface) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
69
		// return $this->choiceList;
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
		// }
71
		
72
		// if no values preset yet return empty list
73
		$this->choiceList = new ArrayChoiceList($this->facets, $value);
74
// 		dump($this->facets);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
75
		return $this->choiceList;
76
	}
77
78
	/**
79
	 *
80
	 * {@inheritDoc}
81
	 *
82
	 * @see \Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface::loadChoicesForValues()
83
	 *
84
	 */
85 View Code Duplication
	public function loadChoicesForValues(array $values, $value = 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...
86
		// is called on form submit after loadValuesForChoices of form create and loadChoiceList of form view create
87
		$choices = array();
88
		foreach($values as $key => $val) {
89
			// we use a DataTransformer, thus only plain values arrive as choices which can be used directly as value
90
			if(is_callable($value)) {
91
				$choices[$key] = (string)call_user_func($value, $val, $key);
92
			} else {
93
				$choices[$key] = $val;
94
			}
95
		}
96
		
97
// 		dump($values);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
		// this has to be done by yourself: array( label => value )
99
		// $labeledValues = MyLabelService::getLabels($values);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
100
		
101
		// // reset internal choice list
102
		// $this->choiceList = new ArrayChoiceList($labeledValues, $value);
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
		
104
		return $choices;
105
	}
106
}