Conditions | 2 |
Paths | 2 |
Total Lines | 90 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
55 | 'l.contentclassattribute_id AS ezcontentobject_link_contentclassattribute_id', |
||
56 | 'l.from_contentobject_id AS ezcontentobject_link_from_contentobject_id', |
||
57 | 'l.from_contentobject_version AS ezcontentobject_link_from_contentobject_version', |
||
58 | 'l.relation_type AS ezcontentobject_link_relation_type', |
||
59 | 'l.to_contentobject_id AS ezcontentobject_link_to_contentobject_id' |
||
60 | ) |
||
61 | ->from( |
||
62 | Gateway::CONTENT_RELATION_TABLE, 'l' |
||
63 | ); |
||
64 | |||
65 | return $query; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Create an update query for setting Content item Version status. |
||
70 | */ |
||
71 | public function getSetVersionStatusQuery( |
||
72 | int $contentId, |
||
73 | int $versionNo, |
||
74 | int $versionStatus |
||
75 | ): DoctrineQueryBuilder { |
||
76 | $query = $this->connection->createQueryBuilder(); |
||
77 | $query |
||
78 | ->update(Gateway::CONTENT_VERSION_TABLE) |
||
79 | ->set('status', ':status') |
||
80 | ->set('modified', ':modified') |
||
81 | ->where('contentobject_id = :contentId') |
||
82 | ->andWhere('version = :versionNo') |
||
83 | ->setParameter('status', $versionStatus, ParameterType::INTEGER) |
||
84 | ->setParameter('modified', time(), ParameterType::INTEGER) |
||
85 | ->setParameter('contentId', $contentId, ParameterType::INTEGER) |
||
86 | ->setParameter('versionNo', $versionNo, ParameterType::INTEGER); |
||
87 | |||
88 | return $query; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Create a select query to load Content Info data. |
||
93 | * |
||
94 | * @see Gateway::loadContentInfo() |
||
95 | * @see Gateway::loadContentInfoList() |
||
96 | * @see Gateway::loadContentInfoByRemoteId() |
||
97 | * @see Gateway::loadContentInfoByLocationId() |
||
98 | */ |
||
99 | public function createLoadContentInfoQueryBuilder( |
||
100 | bool $joinMainLocation = true |
||
101 | ): DoctrineQueryBuilder { |
||
102 | $queryBuilder = $this->connection->createQueryBuilder(); |
||
103 | $expr = $queryBuilder->expr(); |
||
104 | |||
105 | $joinCondition = $expr->eq('c.id', 't.contentobject_id'); |
||
106 | if ($joinMainLocation) { |
||
107 | // wrap join condition with AND operator and join by a Main Location |
||
108 | $joinCondition = $expr->andX( |
||
109 | $joinCondition, |
||
110 | $expr->eq('t.node_id', 't.main_node_id') |
||
111 | ); |
||
112 | } |
||
113 | |||
114 | $queryBuilder |
||
115 | ->select('c.*', 't.main_node_id AS ezcontentobject_tree_main_node_id') |
||
116 | ->from(Gateway::CONTENT_ITEM_TABLE, 'c') |
||
117 | ->leftJoin( |
||
118 | 'c', |
||
119 | 'ezcontentobject_tree', |
||
120 | 't', |
||
121 | $joinCondition |
||
|
|||
122 | ); |
||
123 | |||
124 | return $queryBuilder; |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * Get query builder for content version objects, used for version loading w/o fields. |
||
129 | * |
||
130 | * Creates a select query with all necessary joins to fetch a complete |
||
131 | * content object. Does not apply any WHERE conditions, and does not contain |
||
132 | * name data as it will lead to large result set {@see createNamesQuery}. |
||
133 | */ |
||
134 | public function createVersionInfoFindQueryBuilder(): DoctrineQueryBuilder |
||
135 | { |
||
136 | $query = $this->connection->createQueryBuilder(); |
||
137 | $expr = $query->expr(); |
||
138 | |||
139 | $query |
||
140 | ->select( |
||
141 | 'v.id AS ezcontentobject_version_id', |
||
142 | 'v.version AS ezcontentobject_version_version', |
||
143 | 'v.modified AS ezcontentobject_version_modified', |
||
144 | 'v.creator_id AS ezcontentobject_version_creator_id', |
||
145 | 'v.created AS ezcontentobject_version_created', |
||
187 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.