SearchLog   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 87.5%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
wmc 9
c 4
b 0
f 2
lcom 0
cbo 2
dl 0
loc 53
ccs 14
cts 16
cp 0.875
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A onBeforeWrite() 0 7 3
A getBreadcrumbs() 0 12 4
A getFiltersArray() 0 4 2
1
<?php
2
/**
3
 * Records search results for future suggestions and analysis
4
 *
5
 * @author Mark Guinn <[email protected]>
6
 * @date 09.20.2013
7
 * @package shop_search
8
 */
9
class SearchLog extends DataObject
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...
10
{
11
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db 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
        'Query'         => 'Varchar(255)',
13
        'Title'         => 'Varchar(255)', // title for breadcrumbs. any new facets added will be reflected here
14
        'Link'          => 'Varchar(255)',
15
        'Filters'       => 'Text', // json
16
        'NumResults'    => 'Int',
17
    );
18
19
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_one 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...
20
        'Member'        => 'Member',
21
        'ParentSearch'  => 'SearchLog', // used in constructing a search breadcrumb
22
    );
23
24
25
    /**
26
     * Generate the title if needed
27
     */
28 5
    protected function onBeforeWrite()
29
    {
30 5
        parent::onBeforeWrite();
31 5
        if (!$this->Title) {
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<SearchLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
32 5
            $this->Title = empty($this->Query) ? "Search" : "Search: {$this->Query}";
0 ignored issues
show
Documentation introduced by
The property Title does not exist on object<SearchLog>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property Query does not exist on object<SearchLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
33 5
        }
34 5
    }
35
36
37
    /**
38
     * @return ArrayList
39
     */
40 5
    public function getBreadcrumbs()
41
    {
42 5
        $out    = new ArrayList();
43 5
        $cur    = $this;
44
45 5
        while ($cur && $cur->exists()) {
46 5
            $out->unshift($cur);
47 5
            $cur = $cur->ParentSearchID > 0 ? $cur->ParentSearch() : null;
48 5
        }
49
50 5
        return $out;
51
    }
52
53
54
    /**
55
     * @return array
56
     */
57
    public function getFiltersArray()
58
    {
59
        return $this->Filters ? json_decode($this->Filters, true) : array();
0 ignored issues
show
Documentation introduced by
The property Filters does not exist on object<SearchLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
60
    }
61
}
62