Intraface_modules_cms_PageGateway::findAllBySite()   F
last analyzed

Complexity

Conditions 27
Paths 8162

Size

Total Lines 160
Code Lines 88

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 67
CRAP Score 50.0688

Importance

Changes 0
Metric Value
cc 27
eloc 88
nc 8162
nop 2
dl 0
loc 160
ccs 67
cts 98
cp 0.6837
crap 50.0688
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
class Intraface_modules_cms_PageGateway
3
{
4
    protected $db;
5
    protected $kernel;
6
    protected $dbquery;
7
    protected $cmssite;
8
    protected $values;
9
10
    /**
11
     *
12
     * @var array page status types
13
     */
14
    public $status_types = array(
15
        0 => 'draft',
16
        1 => 'published'
17
    );
18
19 3
    function __construct($kernel, DB_Sql $db)
20
    {
21 3
        $this->kernel = $kernel;
22 3
        $this->db = $db;
23 3
    }
24
25
    /**
26
     * Returns the possible page types
27
     *
28
     * @return array possible page types
29
     */
30 3
    public function getTypes()
31
    {
32
        return array(
33 3
            1 => 'page',
34 3
            2 => 'article',
35 3
            3 => 'news');
36
    }
37
38 3 View Code Duplication
    function getDBQuery()
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...
39
    {
40 3
        if ($this->dbquery) {
41 3
            return $this->dbquery;
42
        }
43
        return ($this->dbquery = new Intraface_DBQuery($this->kernel, 'cms_page', 'cms_page.intranet_id = '.$this->kernel->intranet->get('id').' AND cms_page.active = 1 AND site_id = ' . $this->cmssite->get('id')));
44
    }
45
46 3
    function setDBQuery($dbquery)
47
    {
48 3
        $this->dbquery = $dbquery;
49 3
    }
50
51 3 View Code Duplication
    function findById($id)
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...
52
    {
53
        $this->db->query("SELECT id, site_id FROM cms_page WHERE id = " . (int)$id . " AND intranet_id = " . $this->kernel->intranet->get('id'));
54 3
        if (!$this->db->nextRecord()) {
55
            return false;
56
        }
57
        $site = new CMS_Site($this->kernel, $this->db->f('site_id'));
58
        $object = new CMS_Page($site, (int)$id);
59
        return $object;
60
    }
61
62
    function findBySiteIdAndIdentifier($site_id, $identifier)
63
    {
64
        $identifier = strip_tags($identifier);
65
66 View Code Duplication
        if (!empty($identifier)) {
67
            $this->db->query("SELECT site_id, id FROM cms_page WHERE identifier = '" . $identifier . "' AND intranet_id = " . $this->kernel->intranet->get('id') . " AND active = 1 AND site_id = " . $site_id);
68
        } else {
69
            // @todo choose the default page - vi skal lige have noget med publish og expire date her ogs�
70
            $this->db->query("SELECT site_id, id FROM cms_page WHERE intranet_id = " . $this->kernel->intranet->get('id') . " AND active = 1 AND status_key = 1 AND site_id = " . $site_id . " ORDER BY position ASC LIMIT 1");
71
        }
72
        if (!$this->db->nextRecord()) {
73
            $this->db->query("SELECT site_id, id FROM cms_page WHERE id = " . (int)$identifier . " AND intranet_id = " . $this->kernel->intranet->get('id') . " AND active = 1 AND site_id = " . $site_id);
74
            if (!$this->db->nextRecord()) {
75
                return false;
76
            }
77
        }
78
        return new CMS_Page(new CMS_Site($this->kernel, $this->db->f('site_id')), $this->db->f('id'));
79
    }
80
81
    /**
82
     *
83
     * @param $site
84
     * @param object $page CMS_Page used when finding submenu in XMLRPC/shop/Server0030.php method getPage
85
     * @todo remove $page parameter and find another way to generate submenu
86
     * @return unknown_type
87
     */
88 3
    function findAllBySite($site, $page = null)
89
    {
90 3
        $this->cmssite = $site;
91 3
        $pages = array();
0 ignored issues
show
Unused Code introduced by
$pages is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
92
93 3
        if ($this->getDBQuery()->checkFilter('type') && $this->getDBQuery()->getFilter('page') == 'all') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if 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 if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
94
            // no condition isset
95
            // $sql_type = "";
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
96
        } else {
97
            // with int it will never be a fake searcy
98 3
            $type = $this->getDBQuery()->getFilter('type');
99 3
            if ($type == '') {
100 3
                $type = 'page'; // Standard
101 3
            }
102
103 3
            if ($type != 'all') {
104 3
                $type_key = array_search($type, $this->getTypes());
105 3
                if ($type_key === false) {
106
                    throw new Exception("Invalid type '".$type."' set with CMS_PAGE::dbquery::setFilter('type') in CMS_Page::getList");
107
                }
108
109 3
                $this->getDBQuery()->setCondition("type_key = ".$type_key);
110 3
            }
111
        }
112
113
114
        // hvis en henter siderne uden for systemet
115 3
        $sql_expire = '';
0 ignored issues
show
Unused Code introduced by
$sql_expire is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
116 3
        $sql_publish = '';
0 ignored issues
show
Unused Code introduced by
$sql_publish is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
117
        // @todo This need to be corrected
118 3
        if (!is_object($this->kernel->user)) {
119
            $this->getDBQuery()->setCondition("(date_expire > NOW() OR date_expire = '0000-00-00 00:00:00') AND (date_publish < NOW() AND status_key > 0 AND hidden = 0)");
120
        }
121
122 3
        switch ($this->getDBQuery()->getFilter('type')) {
123 3
            case 'page':
124
                $this->getDBQuery()->setSorting("position ASC");
125
                break;
126 3
            case 'news':
127
                $this->getDBQuery()->setSorting("date_publish DESC");
128
                break;
129 3
            case 'article':
130 1
                $this->getDBQuery()->setSorting("position, date_publish DESC");
131 1
                break;
132 3
            default:
133 3
                $this->getDBQuery()->setSorting("date_publish DESC");
134 3
                break;
135 3
        }
136
137
        // rekursiv funktion til at vise siderne
138 3
        $pages = array();
139 3
        $go = true;
0 ignored issues
show
Unused Code introduced by
$go is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
140 3
        $n = 0; // level
141
        // $o = 0; //
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
142 3
        $i = 0; // page counter
143
        // $level = 1;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
144 3
        $cmspage = array();
145 3
        $cmspage[0] = new DB_Sql;
146
147
        // Benyttes til undersider.
148 3
        $dbquery_original = clone $this->getDBQuery();
149 3
        $dbquery_original->storeResult('', '', 'toplevel'); // sikre at der ikke bliver gemt ved undermenuer.
150
151
152 3
        $keywords = $this->getDBQuery()->getKeyword();
153 3
        if (isset($keywords) && is_array($keywords) && count($keywords) > 0 && $type == 'page') {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if 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 if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
154
            // If we are looking for pages, and there is keywords, we probaly want from more than one level
155
            // So we add nothing about level to condition.
156 3
        } elseif ($this->getDBQuery()->checkFilter('level') && $type == 'page') { // $level == 'sublevel' &&
0 ignored issues
show
Bug introduced by
The variable $type does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Unused Code Comprehensibility introduced by
38% 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...
157
158
            // Til at finde hele menuen p� valgt level.
159
            $page_tree = $page->get('page_tree');
160
            $level = (int)$this->getDBQuery()->getFilter('level');
161
            if (isset($page_tree[$level - 1]) && is_array($page_tree[$level - 1])) {
162
                $child_of_id = $page_tree[$level - 1]['id'];
163
            } else {
164
                $child_of_id = 0;
165
            }
166
167
            $this->getDBQuery()->setCondition('child_of_id = '.$child_of_id);
168
            // $cmspage[0]->query("SELECT *, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk FROM cms_page WHERE active=1 AND child_of_id = ".$this->id. $sql_expire . $sql_publish . " ORDER BY id");
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...
169
        } else {
170 3
            $this->getDBQuery()->setCondition('child_of_id = 0');
171
            // $cmspage[0]->query("SELECT *, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk FROM cms_page WHERE ".$sql_type." site_id = " . $this->cmssite->get('id') . " AND child_of_id = 0 AND active = 1 " . $sql_expire . $sql_publish . $sql_order);
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...
172
        }
173
174 3
        $cmspage[0] = $this->getDBQuery()->getRecordset("cms_page.id, title, identifier, status_key, navigation_name, date_publish, child_of_id, pic_id, description, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk", '', false); //
175
176 3
        while (true) {
177 3
            while ($cmspage[$n]->nextRecord()) {
178 1
                $pages[$i]['id'] = $cmspage[$n]->f('id');
179
180 1
                $pages[$i]['title'] = $cmspage[$n]->f('title');
181 1
                $pages[$i]['identifier'] = $cmspage[$n]->f('identifier');
182 1
                $pages[$i]['navigation_name'] = $cmspage[$n]->f('navigation_name');
183 1
                $pages[$i]['date_publish_dk'] = $cmspage[$n]->f('date_publish_dk');
184 1
                $pages[$i]['date_publish'] = $cmspage[$n]->f('date_publish');
185 1
                $pages[$i]['child_of_id'] = $cmspage[$n]->f('child_of_id');
186 1
                $pages[$i]['level'] = $n;
187
188 1
                if (empty($pages[$i]['identifier'])) {
189
                    $pages[$i]['identifier'] = $pages[$i]['id'];
190
                }
191 1
                if (empty($pages[$i]['navigation_name'])) {
192
                    $pages[$i]['navigation_name'] = $pages[$i]['title'];
193
                }
194
195 1
                $pages[$i]['status'] = $this->status_types[$cmspage[$n]->f('status_key')];
196
197
                // @todo hvad er det her til
198 1
                $pages[$i]['new_status'] = 'published';
199 1
                if ($pages[$i]['status'] == 'published') {
200
                    $pages[$i]['new_status'] = 'draft';
201
                }
202
                // hertil slut
203
204
                // denne b�r laves om til picture - og s� f�r man alle nyttige oplysninger ud
205 1
                $pages[$i]['pic_id'] = $cmspage[$n]->f('pic_id');
206 1
                $pages[$i]['picture'] = $this->getPicture($cmspage[$n]->f('pic_id'));
207
208
                //$pages[$i]['picture'] = $cmspage[$n]->f('pic_id');
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% 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...
209 1
                $pages[$i]['description'] = $cmspage[$n]->f('description');
210
211
                // til google sitemaps
212
                // sp�rgsm�let er om vi ikke skal starte et objekt op for hver pages
213
214 1
                $pages[$i]['url'] = $this->cmssite->get('url') . $pages[$i]['identifier'] . '/';
215 1
                $pages[$i]['url_self'] = $pages[$i]['identifier'] . '/';
216 1
                $pages[$i]['changefreq'] = 'weekly';
217 1
                $pages[$i]['priority'] = 0.5;
218
219 1
                $i++;
220
                // $o = $n + 1;
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
221
222 1
                if ($this->getDBQuery()->getFilter('type') == 'page' and $this->getDBQuery()->getFilter('level') == 'alllevels') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
223
                    $dbquery[$n + 1] = clone $dbquery_original;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dbquery was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dbquery = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
224
                    $dbquery[$n + 1]->setCondition("child_of_id = ".$cmspage[$n]->f("id"));
0 ignored issues
show
Bug introduced by
The variable $dbquery does not seem to be defined for all execution paths leading up to this point.

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:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

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

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
225
                    $cmspage[$n + 1] = $dbquery[$n + 1]->getRecordset("id, title, identifier, navigation_name, date_publish, child_of_id, pic_id, status_key, description, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk", '', false);
226
227
                    // if (!array_key_exists($n + 1, $cmspage) OR !is_object($cmspage[$n + 1])) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
228
                    //	$cmspage[$n + 1] = new DB_Sql;
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% 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...
229
                    //}
230
                    // $cmspage[$n + 1]->query("SELECT *, DATE_FORMAT(date_publish, '%d-%m-%Y') AS date_publish_dk FROM cms_page WHERE active=1 AND child_of_id = ".$cmspage[$n]->f("id"). $sql_expire . $sql_publish . " ORDER BY id");
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% 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...
231
232
                    if ($cmspage[$n + 1]->numRows() != 0) {
233
                        $n++;
234
                        continue;
235
                    }
236
                }
237 1
            }
238
239 3
            if ($n == 0) {
240 3
                break;
241
            }
242
243
            $n--;
244
        }
245
246 3
        return $pages;
247
    }
248
249 1 View Code Duplication
    function getPicture($pic_id)
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...
250
    {
251 1
        $shared_filehandler = $this->kernel->useModule('filemanager');
252 1
        $shared_filehandler->includeFile('AppendFile.php');
253
254 1
                $tmp_filehandler = new FileHandler($this->kernel, $pic_id);
255 1
                $this->value['picture']['id']                   = $pic_id;
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
256 1
                $this->value['picture']['original']['icon_uri'] = $tmp_filehandler->get('icon_uri');
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
257 1
                $this->value['picture']['original']['name']     = $tmp_filehandler->get('file_name');
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
258 1
                $this->value['picture']['original']['width']    = $tmp_filehandler->get('width');
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
259 1
                $this->value['picture']['original']['height']   = $tmp_filehandler->get('height');
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
260 1
                $this->value['picture']['original']['file_uri'] = $tmp_filehandler->get('file_uri');
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
261
262 1
        if ($tmp_filehandler->get('is_image')) {
263
            $tmp_filehandler->createInstance();
264
            $instances = $tmp_filehandler->instance->getList('include_hidden');
265
            foreach ($instances as $instance) {
266
                $this->value['picture'][$instance['name']]['file_uri'] = $instance['file_uri'];
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
267
                $this->value['picture'][$instance['name']]['name']     = $instance['name'];
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
268
                $this->value['picture'][$instance['name']]['width']    = $instance['width'];
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
269
                $this->value['picture'][$instance['name']]['height']   = $instance['height'];
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
270
            }
271
        }
272
273 1
            return $this->value['picture'];
0 ignored issues
show
Bug introduced by
The property value does not seem to exist. Did you mean values?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
274
    }
275
276
    /**
277
     * Returns the possible page types but with a binary index
278
     *
279
     * @return array possible page types with binary index
280
     */
281
    public static function getTypesWithBinaryIndex()
282
    {
283
        return array(
284
            1 => 'page',
285
            2 => 'article',
286
            4 => 'news');
287
    }
288
289
    function get($key)
290
    {
291
        return $this->values[$key];
292
    }
293
}
294