1 | <?php |
||
38 | class Query extends BaseQuery implements QueryInterface |
||
39 | { |
||
40 | /** |
||
41 | * @var string action that this query performs |
||
42 | */ |
||
43 | public $action; |
||
44 | |||
45 | /** |
||
46 | * @var array query options e.g. raw, batch |
||
47 | */ |
||
48 | public $options = []; |
||
49 | |||
50 | /** |
||
51 | * @var string the COUNT expression |
||
52 | */ |
||
53 | public $count; |
||
54 | |||
55 | /** |
||
56 | * @var int the default number of seconds that query results can remain valid in cache. |
||
57 | * Use 0 to indicate that the cached data will never expire. And use a negative number to indicate |
||
58 | * query cache should not be used. |
||
59 | * @see cache() |
||
60 | */ |
||
61 | public $queryCacheDuration; |
||
62 | 2 | ||
63 | /** |
||
64 | 2 | * @var Dependency the dependency to be associated with the cached query result for this command |
|
65 | * @see cache() |
||
66 | */ |
||
67 | public $queryCacheDependency; |
||
68 | 2 | ||
69 | /** |
||
70 | 2 | * @param null|Connection $db |
|
71 | * @throws Exception |
||
72 | * @return Command |
||
73 | */ |
||
74 | public function createCommand($db = null) |
||
90 | |||
91 | /** |
||
92 | * Enables query cache for this command. |
||
93 | * @param int $duration the number of seconds that query result of this command can remain valid in the cache. |
||
94 | * If this is not set, the value of [[Connection::queryCacheDuration]] will be used instead. |
||
95 | * Use 0 to indicate that the cached data will never expire. |
||
96 | * @param Dependency $dependency the cache dependency associated with the cached query result |
||
97 | * @return $this the command object itself |
||
98 | */ |
||
99 | public function cache($duration = null, $dependency = null) |
||
105 | |||
106 | public function one($db = null) |
||
117 | |||
118 | 2 | public function count($q = '*', $db = null) |
|
123 | } |
||
124 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.