MslsOptionsTaxTerm   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B check_base() 0 33 7
1
<?php
2
/**
3
 * MslsOptionsTaxTerm
4
 * @author Dennis Ploetner <[email protected]>
5
 * @since 0.9.8
6
 */
7
8
namespace lloc\Msls;
9
10
/**
11
 * Tag options
12
 * @package Msls
13
 */
14
class MslsOptionsTaxTerm extends MslsOptionsTax {
15
16
	/**
17
	 * Base option
18
	 * @var string
19
	 */
20
	protected $base_option = 'tag_base';
21
22
	/**
23
	 * Base definition
24
	 * @var string
25
	 */
26
	protected $base_defined = 'tag';
27
28
	/**
29
	 * Rewrite with front
30
	 * @var bool
31
	 */
32
	public $with_front = true;
33
34
	/**
35
	 * Check and correct URL
36
	 *
37
	 * @param string $url
38
	 * @param MslsOptions $options
39
	 * @return string
40
	 */
41
	public function check_base( $url, $options ) {
42
		if ( ! is_string( $url ) || empty( $url ) ) {
43
			return $url;
44
		}
45
46
		global $wp_rewrite;
47
48
		$base_defined = $options->base_defined;
0 ignored issues
show
Documentation introduced by
The property base_defined does not exist on object<lloc\Msls\MslsOptions>. 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...
49
50
		$permastruct = $wp_rewrite->get_extra_permastruct( $options->get_tax_query() );
51
		if ( $permastruct ) {
52
			$permastruct = explode( '/', $permastruct );
53
			end( $permastruct );
54
			$permastruct = prev( $permastruct );
55
			if ( false !== $permastruct ) {
56
				$base_defined = $permastruct;
57
			}
58
		}
59
60
		$base_option = get_option( $options->base_option );
0 ignored issues
show
Documentation introduced by
The property base_option does not exist on object<lloc\Msls\MslsOptions>. 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...
61
		if ( empty( $base_option ) ) {
62
			$base_option = $options->base_defined;
0 ignored issues
show
Documentation introduced by
The property base_defined does not exist on object<lloc\Msls\MslsOptions>. 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...
63
		}
64
65
		if ( $base_defined != $base_option ) {
66
			$search  = '/' . $base_defined . '/';
67
			$replace = '/' . $base_option . '/';
68
			$count   = 1;
69
			$url     = str_replace( $search, $replace, $url, $count );
70
		}
71
72
		return $url;
73
	}
74
75
}
76