Completed
Push — master ( 8a340c...157d96 )
by Lars
03:22
created

Kint_Objects_Smarty::parse()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 41
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 29.6062

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 41
ccs 5
cts 22
cp 0.2273
rs 6.7272
cc 7
eloc 21
nc 13
nop 1
crap 29.6062
1
<?php
2
3
namespace kint\parsers\objects;
4
5
use kint\inc\KintObject;
6
7
/**
8
 * Class Kint_Objects_Smarty
9
 */
10
class Kint_Objects_Smarty extends KintObject
11
{
12
  /**
13
   * @param $variable
14
   *
15
   * @return array|bool
16
   */
17 2
  public function parse(&$variable)
18
  {
19
    /** @noinspection PhpUndefinedClassInspection */
20
    if (
21 2
        !defined('\Smarty::SMARTY_VERSION') # lower than 3.x
22 2
        ||
23
        !$variable instanceof \Smarty
0 ignored issues
show
Bug introduced by
The class Smarty does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
24 2
    ) {
25 2
      return false;
26
    }
27
28
    /** @noinspection PhpUndefinedClassInspection */
29
    $this->name = 'object Smarty (v' . substr(Smarty::SMARTY_VERSION, 7) . ')'; # trim 'Smarty-'
30
31
    $assigned = $globalAssigns = array();
32
    /** @noinspection PhpUndefinedFieldInspection */
33
    foreach ($variable->tpl_vars as $name => $var) {
34
      $assigned[$name] = $var->value;
35
    }
36
37
    /** @noinspection PhpUndefinedClassInspection */
38
    foreach (Smarty::$global_tpl_vars as $name => $var) {
39
      if ($name === 'SCRIPT_NAME') {
40
        continue;
41
      }
42
43
      $globalAssigns[$name] = $var->value;
44
    }
45
46
    /** @noinspection PhpUndefinedMethodInspection */
47
    return array(
48
        'Assigned'          => $assigned,
49
        'Assigned globally' => $globalAssigns,
50
        'Configuration'     => array(
51
            'Compiled files stored in' => isset($variable->compile_dir)
52
                ? $variable->compile_dir
53
                : $variable->getCompileDir(),
54
        ),
55
    );
56
57
  }
58
}
59