Conditions | 7 |
Paths | 64 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 21 |
CRAP Score | 7.0322 |
Changes | 0 |
1 | <?php |
||
16 | 13 | public function createService(ServiceLocatorInterface $serviceLocator) |
|
17 | { |
||
18 | 13 | $config = $serviceLocator->get('Config'); |
|
19 | |||
20 | 13 | if (isset($config['view_manager']['template_path_stack'])) { |
|
21 | 13 | $templatesPathStack = $config['view_manager']['template_path_stack']; |
|
22 | 13 | } |
|
23 | 13 | if (isset($config['asset_manager']['resolver_configs']['paths'])) { |
|
24 | 13 | $assetsPaths = $config['asset_manager']['resolver_configs']['paths']; |
|
25 | 13 | } |
|
26 | 13 | $templateAssetsResolver = new TemplateAssetsResolver($assetsPaths, $templatesPathStack); |
|
27 | |||
28 | 13 | $resolverCfg = $config['template_assets_resolver']; |
|
29 | 13 | if (isset($resolverCfg['match_patterns']['template_name'])) { |
|
30 | 13 | $templateAssetsResolver->setPatternTemplateName($resolverCfg['match_patterns']['template_name']); |
|
31 | 13 | } |
|
32 | 13 | if (isset($resolverCfg['match_patterns']['global_asset'])) { |
|
33 | 13 | $templateAssetsResolver->setPatternGlobalAssets($resolverCfg['match_patterns']['global_asset']); |
|
34 | 13 | } |
|
35 | 13 | if (isset($resolverCfg['global_folder_name'])) { |
|
36 | 13 | $templateAssetsResolver->setGlobalFolderName($resolverCfg['global_folder_name']); |
|
37 | 13 | } |
|
38 | 13 | if (isset($resolverCfg['public_path'])) { |
|
39 | $templateAssetsResolver->setPublicPath($resolverCfg['public_path']); |
||
40 | } |
||
41 | |||
42 | |||
43 | 13 | return $templateAssetsResolver; |
|
44 | } |
||
45 | } |
||
46 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: