PrettyPhoto   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 11
lcom 0
cbo 4
dl 0
loc 54
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
D include_code() 0 36 10
A block() 0 6 1
1
<?php
2
3
class PrettyPhoto extends Object
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    private static $themes = array("dark_rounded", "dark_square", "facebook", "light_rounded", "light_square");
0 ignored issues
show
Unused Code introduced by
The property $themes is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
6
7
    private static $theme = "";
0 ignored issues
show
Unused Code introduced by
The property $theme is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
8
9
    private static $more_config = array("social_tools" =>  false);
0 ignored issues
show
Unused Code introduced by
The property $more_config is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
10
11
    private static $selector = "body";
0 ignored issues
show
Unused Code introduced by
The property $selector is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
12
13
    public static function include_code()
14
    {
15
        if (Director::is_ajax()) {
16
            self::block();
17
        } else {
18
            Requirements::javascript(THIRDPARTY_DIR."/jquery/jquery.js");
19
            Requirements::javascript('prettyphoto/javascript/jquery.prettyPhoto.js');
20
            Requirements::css('prettyphoto/css/prettyPhoto.css');
21
22
            $config = '';
23
            $theme = Config::inst()->get("PrettyPhoto", "theme");
24
            $moreConfigArray = Config::inst()->get("PrettyPhoto", "more_config");
25
            foreach ($moreConfigArray as $key => $value) {
0 ignored issues
show
Bug introduced by
The expression $moreConfigArray of type array|integer|double|string|boolean is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. 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:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
26
                if ($value === false) {
27
                    $value = "false";
28
                } elseif ($value === true) {
29
                    $value = "true";
30
                } elseif ($value === intval($value)) {
0 ignored issues
show
Unused Code introduced by
This elseif statement is empty, and could be removed.

This check looks for the bodies of elseif statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These elseif bodies can be removed. If you have an empty elseif but statements in the else branch, consider inverting the condition.

Loading history...
31
                    //$value = $value;
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...
32
                } else {
33
                    $value = " '$value' ";
34
                }
35
                $moreConfigArray[$key] = "$key: $value";
36
            }
37
            if ($theme) {
38
                $config .= "theme: '".$theme."'";
39
            }
40
            if ($config && count($moreConfigArray)) {
41
                $config .= ", ";
42
            }
43
            if (count($moreConfigArray)) {
44
                $config .= implode(",", $moreConfigArray);
45
            }
46
            Requirements::customScript('PrettyPhotoInitConfigs = {'.$config.'}; jQuery(document).ready(function(){PrettyPhotoLoader.load("'.Config::inst()->get("PrettyPhoto", "selector").'")});', "prettyPhotoCustomScript");
47
        }
48
    }
49
50
    public static function block()
51
    {
52
        Requirements::block('prettyphoto/javascript/jquery.prettyPhoto.js');
53
        Requirements::block('prettyphoto/css/prettyPhoto.css');
54
        Requirements::block("prettyPhotoCustomScript");
55
    }
56
}
57