http://phing.info/

Source Code Coverage

Designed for use with PHPUnit2, Xdebug and Phing.

Methods: 7 LOC: 148 Statements: 26

Source file Statements Methods Total coverage
Abstract.php 96.2% 100.0% 97.0%
   
1
<?php
2
/**
3
 * Xyster Framework
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://www.opensource.org/licenses/bsd-license.php
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to xyster@devweblog.org so we can send you a copy immediately.
14
 *
15
 * @category  Xyster
16
 * @package   Xyster_Collection
17
 * @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org)
18
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
19
 */
20
/**
21
 * @see Xyster_Collection_Map_Interface
22
 */
23 1
require_once 'Xyster/Collection/Map/Interface.php';
24
/**
25
 * Abstract class for key-based collections
26
 *
27
 * @category  Xyster
28
 * @package   Xyster_Collection
29
 * @copyright Copyright (c) 2007 Irrational Logic (http://devweblog.org)
30
 * @license   http://www.opensource.org/licenses/bsd-license.php New BSD License
31
 */
32
abstract class Xyster_Collection_Map_Abstract implements Xyster_Collection_Map_Interface
33
{
34
	/**
35
	 * Tests to see whether the map contains the key supplied
36
	 *
37
	 * If the supplied value is an object, and the map allows objects as keys,
38
	 * the comparison will be done for identity (===) and not for value (==).
39
	 *
40
	 * This method is an alias to ArrayAccess::offsetExists
41
	 *
42
	 * @param mixed $key The key to test
43
	 * @return boolean Whether the map contains the supplied key
44
	 */
45
	public function containsKey( $key )
46
	{
47 6
		return $this->offsetExists($key);
48
	}
49
50
	/**
51
	 * Tests to see whether the map contains the value supplied
52
	 *
53
	 * If the supplied value is an object, the comparison will be done for
54
	 * identity (===) and not for value (==).
55
	 *
56
	 * @param mixed $item The item to test
57
	 * @return boolean Whether the map contains the supplied value
58
	 */
59
	public function containsValue( $item )
60
	{
61 4
		foreach( $this->values() as $value ) {
62 4
			if ( $item === $value ) {
63 4
				return true;
64 0
			}
65 3
		}
66 2
		return false;
67
	}
68
69
	/**
70
	 * Gets the value corresponding to the supplied key
71
	 *
72
	 * This method could return null if the value is null, or if the value was
73
	 * not found.  Use {@link containsValue} to check which is true.
74
	 *
75
	 * @param mixed $key
76
	 * @return mixed The value found, or null if none
77
	 */
78
	public function get( $key )
79
	{
80 82
		return $this->offsetGet($key);
81
	}
82
83
	/**
84
	 * Tests to see if the collection contains no elements
85
	 *
86
	 * The return value from this method should be equivalent to
87
	 * <code>( $collection->count() == 0 )</code>.
88
	 *
89
	 * @return boolean Whether this collection has no elements
90
	 */
91
	public function isEmpty()
92
	{
93 3
		return $this->count() == 0;
94
	}
95
96
	/**
97
	 * Combines this map with the supplied map
98
	 *
99
	 * The values in the supplied map will take precedence if this map and the
100
	 * supplied map have duplicate keys.
101
	 *
102
	 * @param Xyster_Map_Interface $map
103
	 * @return boolean Whether the map changed as a result of this method
104
	 */
105
	public function merge( Xyster_Collection_Map_Interface $map )
106
	{
107 8
		$changed = false;
108 8
		foreach( $map as $key=>$value ) {
109 7
		    if ( $value instanceof Xyster_Collection_Map_Entry ) {
110 5
		        if ( !$changed && $this->get($value->getKey()) !== $value->getValue() ) {
111 5
		            $changed = true;
112 5
		        }
113 5
		        $this->set($value->getKey(), $value->getValue());
114 5
		    } else {
115 2
    			if ( !$changed && $this->get($key) !== $value ) {
116 2
				    $changed = true;
117 2
			    }
118 2
			    $this->set($key, $value);
119
		    }
120 7
		}
121 8
		return $changed;
122
	}
123
124
	/**
125
	 * Removes the mapping for the specified key
126
	 *
127
	 * This method is an alias to ArrayAccess::offsetUnset
128
	 *
129
	 * @param mixed $key
130
	 */
131
	public function remove( $key )
132
	{
133 13
		$this->offsetUnset($key);
134
	}
135
136
	/**
137
	 * Sets a mapping for the key and value supplied
138
	 *
139
	 * This method is an alias to ArrayAccess::offsetSet
140
	 *
141
	 * @param mixed $key
142
	 * @param mixed $value
143
	 */
144
	public function set( $key, $value )
145
	{
146 105
		$this->offsetSet($key,$value);
147
	}
148
}


Report generated at 2007-11-05T09:09:01-05:00