ar_html_table::foot()   B
last analyzed

Complexity

Conditions 6
Paths 6

Size

Total Lines 20

Duplication

Lines 20
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
nc 6
nop 2
dl 20
loc 20
rs 8.9777
c 0
b 0
f 0
ccs 0
cts 20
cp 0
crap 42
1
<?php
2
	ar_pinp::allow('ar_html_table');
3
4
	class ar_html_table extends ar_htmlElement {
5
6
		private $rowHeaderAttributes = null;
7
		private $rowHeaders = null;
8
9
		public function __construct( $data= null, $attributes = null, $childNodes = null, $parentNode = null ) {
10
			parent::__construct( 'table', $attributes , $childNodes, $parentNode );
11
			if ( isset($data) ) {
12
				$this->body( $data );
13
			}
14
		}
15
16
		public function body( $data ) {
17
			if (!is_array($data) ) {
18
				$data = array( $data );
19
			}
20
			$rows =	$this->getRows($data)->setAttribute( 'class', array(
21
				'tableFirstLast' => ar::listPattern( 'tableFirst .*', '.* tableLast'),
22
				'tableOddEven'   => ar::listPattern( '(tableOdd tableEven?)*' )
23
			) );
24
			$this->appendChild(
25
				ar_html::tag(
26
					'tbody', $rows
27
				)
28
			);
29
			return $this;
30
		}
31
32
		private function getRows( $list ) {
33
			$nodes   = ar_html::nodes();
34
			foreach ( $list as $key => $content ) {
35
				if ( !is_array( $content ) ) {
36
					$content = array( $content );
37
				}
38
				$cells = $this->getCells( $content, 'td')->setAttribute('class', array(
39
					'tableOddEven'   => ar::listPattern( '(tableOdd tableEven?)*' ),
40
					'tableFirstLast' => ar::listPattern( 'tableFirst .*', '.* tableLast')
41
				) );
42
				$nodes[] = ar_html::tag( 'tr', ar_html::nodes( $header, $cells ) );
0 ignored issues
show
Bug introduced by
The variable $header does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
43
			}
44
			return $nodes;
45
		}
46
47
		private function getCells( $list, $tag = 'td') {
48
			$nodes   = ar_html::nodes();
49
			foreach ($list as $key => $content ) {
50
				$nodes[] = ar_html::el($tag, $content);
51
			}
52
			return $nodes;
53
		}
54
55 View Code Duplication
		public function head( $list, $attributes = null ) {
56
			if ( is_array($list) ) {
57
				$nodes = $this->getCells( $list, 'th' );
58
				$head = $this->thead->firstChild; //current( $this->getElementsByTagName('thead') );
0 ignored issues
show
Documentation introduced by
The property thead does not exist on object<ar_html_table>. 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...
59
				if ( !isset($head) ) {
60
					$head = ar_html::tag( 'thead', $attributes );
61
					if ( $foot = $this->tfoot->firstChild ) {
0 ignored issues
show
Documentation introduced by
The property tfoot does not exist on object<ar_html_table>. 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...
62
						$this->insertBefore( $head, $foot );
63
					} else if ( $body = $this->tbody->firstChild ) {
0 ignored issues
show
Documentation introduced by
The property tbody does not exist on object<ar_html_table>. 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...
64
						$this->insertBefore( $head, $body );
65
					} else {
66
						$this->appendChild( $head );
67
					}
68
				} else if (isset($attributes)) {
69
					$head->setAttributes( $attributes );
70
				}
71
				$head->appendChild( ar_html::tag( 'tr', $nodes ) );
72
			}
73
			return $this;
74
		}
75
76 View Code Duplication
		public function foot( $list, $attributes = null ) {
77
			if ( is_array( $list ) ) {
78
				$nodes = $this->getCells( $list, 'td' );
79
				$foot = $this->tfoot->lastChild;
0 ignored issues
show
Documentation introduced by
The property tfoot does not exist on object<ar_html_table>. 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...
80
				if ( !isset($foot) ) {
81
					$foot = ar_html::tag( 'tfoot', $attributes );
82
					if ( $head = $this->thead->lastChild ) {
0 ignored issues
show
Documentation introduced by
The property thead does not exist on object<ar_html_table>. 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...
83
						$this->insertBefore( $foot, $head->nextSibling );
84
					} else if ( $body = $this->tbody->firstChild ) {
0 ignored issues
show
Documentation introduced by
The property tbody does not exist on object<ar_html_table>. 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...
85
						$this->insertBefore( $foot, $body );
86
					} else {
87
						$this->appendChild( $foot );
88
					}
89
				} else if (isset( $attributes ) ) {
90
					$foot->setAttributes( $attributes );
91
				}
92
				$foot->appendChild( ar_html::tag( 'tr', $nodes ) );
93
			}
94
			return $this;
95
		}
96
97
		public function rowHeaders( $list, $attributes = array() ) {
98
			foreach ( $list as $key => $value ) {
99
				if ( ! ($value instanceof ar_htmlNode ) || $value->tagName != 'th' ) {
0 ignored issues
show
Documentation introduced by
The property tagName does not exist on object<ar_htmlNode>. 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...
100
					$list[$key] = ar_html::tag( 'th',
101
						array_merge(
102
							(array) $attributes,
103
							array( 'scope' => 'row' )
104
						),
105
						$value
106
					);
107
				}
108
			}
109
			reset($list);
110
			foreach( $this->tbody->lastChild->childNodes as $row ) {
0 ignored issues
show
Documentation introduced by
The property tbody does not exist on object<ar_html_table>. 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...
111
				$row->insertBefore( current($list), $row->firstChild );
112
				next($list);
113
			}
114
			$this->rowHeaders = $list;
115
			$this->rowHeaderAttributes = $attributes;
116
			return $this;
117
		}
118
119
		public function cols() {
120
			$args = func_get_args();
121
			$cols = call_user_func_array( array('ar_html', 'nodes'), $args );
122
			$this->removeChild( $this->colgroup );
0 ignored issues
show
Documentation introduced by
The property colgroup does not exist on object<ar_html_table>. 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...
123
			$this->removeChild( $this->col );
0 ignored issues
show
Documentation introduced by
The property col does not exist on object<ar_html_table>. 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...
124
			$this->insertBefore( $cols, $this->firstChild );
0 ignored issues
show
Documentation introduced by
The property firstChild does not exist on object<ar_html_table>. 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...
125
			return $this;
126
		}
127
128
		public function caption($content, $attributes = null) {
129
			$newCaption = ar_html::tag( 'caption', $content, $attributes );
130
			if ( $caption = $this->caption->firstChild ) {
0 ignored issues
show
Documentation introduced by
The property caption does not exist on object<ar_html_table>. 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...
131
				$this->replaceChild( $newCaption, $caption );
132
			} else {
133
				$this->insertBefore( $newCaption, $this->firstChild );
0 ignored issues
show
Documentation introduced by
The property firstChild does not exist on object<ar_html_table>. 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...
134
			}
135
			return $this;
136
		}
137
	}
138