Passed
Pull Request — master (#2)
by tsms
01:39
created

Calendar_Decorator_Wrapper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fetch() 0 9 2
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4: */
3
4
/**
5
 * Contains the Calendar_Decorator_Wrapper class
6
 *
7
 * PHP versions 4 and 5
8
 *
9
 * LICENSE: Redistribution and use in source and binary forms, with or without
10
 * modification, are permitted provided that the following conditions are met:
11
 * 1. Redistributions of source code must retain the above copyright
12
 *    notice, this list of conditions and the following disclaimer.
13
 * 2. Redistributions in binary form must reproduce the above copyright
14
 *    notice, this list of conditions and the following disclaimer in the
15
 *    documentation and/or other materials provided with the distribution.
16
 * 3. The name of the author may not be used to endorse or promote products
17
 *    derived from this software without specific prior written permission.
18
 *
19
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
20
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22
 * IN NO EVENT SHALL THE FREEBSD PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY
23
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
 *
30
 * @category  Date and Time
31
 * @package   Calendar
32
 * @author    Harry Fuecks <[email protected]>
33
 * @author    Lorenzo Alberton <[email protected]>
34
 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
35
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
36
 * @version   CVS: $Id$
37
 * @link      http://pear.php.net/package/Calendar
38
 */
39
namespace Pear\Calendar\Decorator;
40
41
/**
42
 * Allows Calendar include path to be redefined
43
 * @ignore
44
 */
45
if (!defined('CALENDAR_ROOT')) {
46
    define('CALENDAR_ROOT', 'Calendar'.DIRECTORY_SEPARATOR);
47
}
48
49
/**
50
 * Load Calendar decorator base class
51
 */
52
require_once CALENDAR_ROOT.'Decorator.php';
53
54
/**
55
 * Decorator to help with wrapping built children in another decorator
56
 *
57
 * @category  Date and Time
58
 * @package   Calendar
59
 * @author    Harry Fuecks <[email protected]>
60
 * @author    Lorenzo Alberton <[email protected]>
61
 * @copyright 2003-2007 Harry Fuecks, Lorenzo Alberton
62
 * @license   http://www.debian.org/misc/bsd.license  BSD License (3 Clause)
63
 * @link      http://pear.php.net/package/Calendar
64
 * @access    public
65
 */
66
class Calendar_Decorator_Wrapper extends Calendar_Decorator
67
{
68
    /**
69
     * Constructs Calendar_Decorator_Wrapper
70
     *
71
     * @param object &$Calendar subclass of Calendar
72
     *
73
     * @access public
74
     */
75
    function __construct(&$Calendar)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
76
    {
77
        parent::__construct($Calendar);
78
    }
79
80
    /**
81
     * Wraps objects returned from fetch in the named Decorator class
82
     *
83
     * @param string $decorator name of Decorator class to wrap with
84
     *
85
     * @return object instance of named decorator
86
     * @access public
87
     */
88
    function & fetch($decorator)
89
    {
90
        $Calendar = parent::fetch();
91
        if ($Calendar) {
92
            $ret = new $decorator($Calendar);
93
        } else {
94
            $ret = false;
95
        }
96
        return $ret;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $ret could also return false which is incompatible with the documented return type object. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
97
    }
98
99
    /**
100
     * Wraps the returned calendar objects from fetchAll in the named decorator
101
     *
102
     * @param string $decorator name of Decorator class to wrap with
103
     *
104
     * @return array
105
     * @access public
106
     */
107
    function fetchAll($decorator)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
108
    {
109
        $children = parent::fetchAll();
110
        foreach ($children as $key => $Calendar) {
111
            $children[$key] = new $decorator($Calendar);
112
        }
113
        return $children;
114
    }
115
}
116