BeforeQueryEvent   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Coupling/Cohesion

Dependencies 1

Importance

Changes 6
Bugs 4 Features 1
Metric Value
wmc 12
c 6
b 4
f 1
cbo 1
dl 0
loc 151
rs 10

12 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 15 1
A getConnection() 0 4 1
A getQuery() 0 4 1
A getQueryParameters() 0 4 1
A getQueryOptions() 0 4 1
A getResults() 0 4 1
A setQuery() 0 4 1
A setQueryOptions() 0 4 1
A setQueryParameters() 0 4 1
A setResults() 0 4 1
A setQueryBridge() 0 4 1
A getQueryBridge() 0 4 1
1
<?php
2
/**
3
 * Fwk
4
 *
5
 * Copyright (c) 2011-2014, Julien Ballestracci <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
12
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
13
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
15
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
16
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
17
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
18
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
19
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
21
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
22
 * POSSIBILITY OF SUCH DAMAGE.
23
 *
24
 * PHP Version 5.3
25
 *
26
 * @category   Database
27
 * @package    Fwk
28
 * @subpackage Db
29
 * @author     Julien Ballestracci <[email protected]>
30
 * @copyright  2011-2014 Julien Ballestracci <[email protected]>
31
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
32
 * @link       http://www.nitronet.org/fwk
33
 */
34
namespace Fwk\Db\Events;
35
36
use Fwk\Db\Query;
37
use Fwk\Db\QueryBridge;
38
use Fwk\Events\Event;
39
use Fwk\Db\Connection;
40
41
/**
42
 * This event is fired before a Query is sent to be executed by the Connection
43
 *
44
 * @category Events
45
 * @package  Fwk\Db
46
 * @author   Julien Ballestracci <[email protected]>
47
 * @license  http://www.opensource.org/licenses/bsd-license.php  BSD License
48
 * @link     http://www.nitronet.org/fwk
49
 */
50
class BeforeQueryEvent extends Event
51
{
52
    const EVENT_NAME = 'beforeQuery';
53
54
    /**
55
     * Constructor
56
     *
57
     * @param Connection $connection   The DB Connection
58
     * @param Query      $query        The Query
59
     * @param array      $queryParams  Query Parameters
60
     * @param array      $queryOptions Query Options
61
     * @param mixed      $results      Query results/pre-results
62
     *
63
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
64
     */
65
    public function __construct(Connection $connection, Query $query,
66
        array $queryParams = array(), array $queryOptions = array(),
67
        $results = null
68
    ) {
69
        parent::__construct(
70
            static::EVENT_NAME, array(
71
                'connection'    => $connection,
72
                'query'         => $query,
73
                'queryParameters'   => (array)$queryParams,
74
                'queryOptions'  => (array)$queryOptions,
75
                'results'       => $results,
76
                'bridge'        => null
77
            )
78
        );
79
    }
80
81
    /**
82
     * Returns the Database Connection
83
     *
84
     * @return Connection
85
     */
86
    public function getConnection()
87
    {
88
        return $this->connection;
0 ignored issues
show
Documentation introduced by
The property connection does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
89
    }
90
91
    /**
92
     * Returns the Query
93
     *
94
     * @return Query
95
     */
96
    public function getQuery()
97
    {
98
        return $this->query;
0 ignored issues
show
Documentation introduced by
The property query does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
99
    }
100
101
    /**
102
     * Returns the Query's parameters (i.e values)
103
     *
104
     * @return array
105
     */
106
    public function getQueryParameters()
107
    {
108
        return $this->queryParameters;
0 ignored issues
show
Documentation introduced by
The property queryParameters does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
109
    }
110
111
    /**
112
     * Returns the Query's driver options
113
     *
114
     * @return array
115
     */
116
    public function getQueryOptions()
117
    {
118
        return $this->queryOptions;
0 ignored issues
show
Documentation introduced by
The property queryOptions does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
119
    }
120
121
    /**
122
     * Returns the Query's results (if any)
123
     *
124
     * @return mixed
125
     */
126
    public function getResults()
127
    {
128
        return $this->results;
0 ignored issues
show
Documentation introduced by
The property results does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
129
    }
130
131
    /**
132
     * Defines the Query
133
     *
134
     * @param Query $query The Query
135
     *
136
     * @return void
137
     */
138
    public function setQuery(Query $query)
139
    {
140
        $this->query = $query;
0 ignored issues
show
Documentation introduced by
The property query does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
141
    }
142
143
    /**
144
     * Defines Driver options for this query
145
     *
146
     * @param array $queryOptions Driver options for this query
147
     *
148
     * @return void
149
     */
150
    public function setQueryOptions(array $queryOptions)
151
    {
152
        $this->queryOptions = $queryOptions;
0 ignored issues
show
Documentation introduced by
The property queryOptions does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
153
    }
154
155
    /**
156
     * Defines parameters (i.e values) for the query
157
     *
158
     * @param array $queryParameters Parameters (values) for the Query
159
     *
160
     * @return void
161
     */
162
    public function setQueryParameters(array $queryParameters)
163
    {
164
        $this->queryParameters = $queryParameters;
0 ignored issues
show
Documentation introduced by
The property queryParameters does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
165
    }
166
167
    /**
168
     * Defines Results for this Query
169
     *
170
     * @param mixed $results Query's results
171
     *
172
     * @return void
173
     */
174
    public function setResults($results)
175
    {
176
        $this->results = $results;
0 ignored issues
show
Documentation introduced by
The property results does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
177
    }
178
179
    /**
180
     * Defines the QueryBridge for this query
181
     *
182
     * @param QueryBridge $bridge The QueryBridge used with this Query
183
     *
184
     * @return void
185
     */
186
    public function setQueryBridge(QueryBridge $bridge)
187
    {
188
        $this->bridge = $bridge;
0 ignored issues
show
Documentation introduced by
The property bridge does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
189
    }
190
191
    /**
192
     * Returns the defined QueryBridge for this Query
193
     *
194
     * @return QueryBridge
195
     */
196
    public function getQueryBridge()
197
    {
198
        return $this->bridge;
0 ignored issues
show
Documentation introduced by
The property bridge does not exist on object<Fwk\Db\Events\BeforeQueryEvent>. 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...
199
    }
200
}