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
Pull Request — master (#1)
by
unknown
12:30
created

DependencyInjection/Configuration.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
/*
5
 * This file is part of the Stinger Entity Search package.
6
 *
7
 * (c) Oliver Kotte <[email protected]>
8
 * (c) Florian Meyer <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
namespace StingerSoft\EntitySearchBundle\DependencyInjection;
14
15
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
16
use Symfony\Component\Config\Definition\ConfigurationInterface;
17
use Symfony\Component\HttpKernel\Kernel;
18
19
20
/**
21
 * This is the class that validates and merges configuration from your app/config files
22
 *
23
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
24
 */
25
class Configuration implements ConfigurationInterface {
26
27
	/**
28
	 *
29
	 * {@inheritDoc}
30
	 *
31
	 */
32
	public function getConfigTreeBuilder() {
33
		$treeBuilder = new TreeBuilder('stinger_soft_entity_search');
34
		// @formatter:off
35
		$treeBuilder->getRootNode()->children()
0 ignored issues
show
It seems like you code against a specific sub-type and not the parent class Symfony\Component\Config...\Builder\NodeDefinition as the method children() does only exist in the following sub-classes of Symfony\Component\Config...\Builder\NodeDefinition: Symfony\Component\Config...der\ArrayNodeDefinition. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

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

class MyUser extends 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 sub-classes 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 parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
36
			->booleanNode('enable_indexing')->defaultFalse()->end()
37
			->booleanNode('enable_search')->defaultFalse()->end()
38
			->scalarNode('search_service')->defaultValue('stinger_soft.entity_search.dummy_search_service')->end()
39
			->arrayNode('results')->addDefaultsIfNotSet()
40
				->children()
41
					->integerNode('max_choice_group_count')->defaultValue(10)->end()
42
					->arrayNode('preferred_type_choices')
43
						->prototype('scalar')->end()
44
					->end()
45
					->arrayNode('preferred_filetype_choices')
46
						->prototype('scalar')->end()
47
					->end()
48
					->arrayNode('ingore_patterns')
49
						->prototype('scalar')->end()
50
					->end()
51
				->end()
52
			->end()
53
			->arrayNode('facets')->defaultValue(array('stinger_soft_entity_search.facets.author', 'stinger_soft_entity_search.facets.editors', 'stinger_soft_entity_search.facets.type'))
54
				->prototype('scalar')->end()
55
			->end()
56
			->arrayNode('types')
57
				->useAttributeAsKey('name')
58
				->prototype('array')
59
					->children()
60
						->arrayNode('mappings')
61
							->useAttributeAsKey('name')
62
							->cannotBeEmpty()
63
							->prototype('array')
64
								->children()
65
									->scalarNode('propertyPath')->defaultValue(false)->end()
66
								->end()
67
							->end()
68
						->end()
69
						->arrayNode('persistence')
70
							->children()
71
								->scalarNode('model')->end()
72
							->end()
73
						->end()
74
					->end()
75
				->end()
76
			->end();
77
		// @formatter:on
78
		
79
		return $treeBuilder;
80
	}
81
}
82