Complex classes like DoctrineExpression often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DoctrineExpression, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class DoctrineExpression implements Expression |
||
|
|
|||
| 20 | { |
||
| 21 | /** @var \Doctrine\DBAL\Connection */ |
||
| 22 | private $connection; |
||
| 23 | |||
| 24 | /** @var \Doctrine\DBAL\Platforms\AbstractPlatform */ |
||
| 25 | private $platform; |
||
| 26 | |||
| 27 | public function __construct(Connection $connection) |
||
| 32 | |||
| 33 | /** |
||
| 34 | * Returns the SQL to bind logical expressions together using a logical or. |
||
| 35 | * |
||
| 36 | * lOr() accepts an arbitrary number of parameters. Each parameter |
||
| 37 | * must contain a logical expression or an array with logical expressions. |
||
| 38 | * |
||
| 39 | * Example: |
||
| 40 | * <code> |
||
| 41 | * $q = $dbHandler->createSelectQuery(); |
||
| 42 | * $e = $q->expr; |
||
| 43 | * $q->select( '*' )->from( 'table' ) |
||
| 44 | * ->where( $e->lOr( $e->eq( 'id', $q->bindValue( 1 ) ), |
||
| 45 | * $e->eq( 'id', $q->bindValue( 2 ) ) ) ); |
||
| 46 | * </code> |
||
| 47 | * |
||
| 48 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 49 | * |
||
| 50 | * @return string a logical expression |
||
| 51 | */ |
||
| 52 | public function lOr() |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Combine an array of expression by OR/AND. |
||
| 61 | * |
||
| 62 | * @param array $args |
||
| 63 | * @param string $by |
||
| 64 | * |
||
| 65 | * @return string |
||
| 66 | */ |
||
| 67 | private function combine(array $args, $by) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Returns the SQL to bind logical expressions together using a logical and. |
||
| 86 | * |
||
| 87 | * lAnd() accepts an arbitrary number of parameters. Each parameter |
||
| 88 | * must contain a logical expression or an array with logical expressions. |
||
| 89 | * |
||
| 90 | * Example: |
||
| 91 | * <code> |
||
| 92 | * $q = $dbHandler->createSelectQuery(); |
||
| 93 | * $e = $q->expr; |
||
| 94 | * $q->select( '*' )->from( 'table' ) |
||
| 95 | * ->where( $e->lAnd( $e->eq( 'id', $q->bindValue( 1 ) ), |
||
| 96 | * $e->eq( 'id', $q->bindValue( 2 ) ) ) ); |
||
| 97 | * </code> |
||
| 98 | * |
||
| 99 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 100 | * |
||
| 101 | * @return string a logical expression |
||
| 102 | */ |
||
| 103 | public function lAnd() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Returns the SQL for a logical not, negating the $expression. |
||
| 112 | * |
||
| 113 | * Example: |
||
| 114 | * <code> |
||
| 115 | * $q = $dbHandler->createSelectQuery(); |
||
| 116 | * $e = $q->expr; |
||
| 117 | * $q->select( '*' )->from( 'table' ) |
||
| 118 | * ->where( $e->eq( 'id', $e->not( 'null' ) ) ); |
||
| 119 | * </code> |
||
| 120 | * |
||
| 121 | * @param string $expression |
||
| 122 | * |
||
| 123 | * @return string a logical expression |
||
| 124 | */ |
||
| 125 | public function not($expression) |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Returns the SQL to add values or expressions together. |
||
| 132 | * |
||
| 133 | * add() accepts an arbitrary number of parameters. Each parameter |
||
| 134 | * must contain a value or an expression or an array with values or |
||
| 135 | * expressions. |
||
| 136 | * |
||
| 137 | * Example: |
||
| 138 | * <code> |
||
| 139 | * $q = $dbHandler->createSelectQuery(); |
||
| 140 | * $q->select( '*' )->from( 'table' ) |
||
| 141 | * ->where( $q->expr->add( 'id', 2 ) ); |
||
| 142 | * </code> |
||
| 143 | * |
||
| 144 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 145 | * |
||
| 146 | * @param string|array(string) $... |
||
| 147 | * |
||
| 148 | * @return string an expression |
||
| 149 | */ |
||
| 150 | public function add() |
||
| 156 | |||
| 157 | /** |
||
| 158 | * Returns the SQL to subtract values or expressions from eachother. |
||
| 159 | * |
||
| 160 | * subtract() accepts an arbitrary number of parameters. Each parameter |
||
| 161 | * must contain a value or an expression or an array with values or |
||
| 162 | * expressions. |
||
| 163 | * |
||
| 164 | * Example: |
||
| 165 | * <code> |
||
| 166 | * $q = $dbHandler->createSelectQuery(); |
||
| 167 | * $q->select( '*' )->from( 'table' ) |
||
| 168 | * ->where( $q->expr->subtract( 'id', 2 ) ); |
||
| 169 | * </code> |
||
| 170 | * |
||
| 171 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 172 | * |
||
| 173 | * @param string|array(string) $... |
||
| 174 | * |
||
| 175 | * @return string an expression |
||
| 176 | */ |
||
| 177 | public function sub() |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Returns the SQL to multiply values or expressions by eachother. |
||
| 186 | * |
||
| 187 | * multiply() accepts an arbitrary number of parameters. Each parameter |
||
| 188 | * must contain a value or an expression or an array with values or |
||
| 189 | * expressions. |
||
| 190 | * |
||
| 191 | * Example: |
||
| 192 | * <code> |
||
| 193 | * $q = $dbHandler->createSelectQuery(); |
||
| 194 | * $q->select( '*' )->from( 'table' ) |
||
| 195 | * ->where( $q->expr->multiply( 'id', 2 ) ); |
||
| 196 | * </code> |
||
| 197 | * |
||
| 198 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 199 | * |
||
| 200 | * @param string|array(string) $... |
||
| 201 | * |
||
| 202 | * @return string an expression |
||
| 203 | */ |
||
| 204 | public function mul() |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Returns the SQL to divide values or expressions by eachother. |
||
| 213 | * |
||
| 214 | * divide() accepts an arbitrary number of parameters. Each parameter |
||
| 215 | * must contain a value or an expression or an array with values or |
||
| 216 | * expressions. |
||
| 217 | * |
||
| 218 | * Example: |
||
| 219 | * <code> |
||
| 220 | * $q = $dbHandler->createSelectQuery(); |
||
| 221 | * $q->select( '*' )->from( 'table' ) |
||
| 222 | * ->where( $q->expr->divide( 'id', 2 ) ); |
||
| 223 | * </code> |
||
| 224 | * |
||
| 225 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 226 | * |
||
| 227 | * @param string|array(string) $... |
||
| 228 | * |
||
| 229 | * @return string an expression |
||
| 230 | */ |
||
| 231 | public function div() |
||
| 237 | |||
| 238 | /** |
||
| 239 | * Returns the SQL to check if two values are equal. |
||
| 240 | * |
||
| 241 | * Example: |
||
| 242 | * <code> |
||
| 243 | * $q = $dbHandler->createSelectQuery(); |
||
| 244 | * $q->select( '*' )->from( 'table' ) |
||
| 245 | * ->where( $q->expr->eq( 'id', $q->bindValue( 1 ) ) ); |
||
| 246 | * </code> |
||
| 247 | * |
||
| 248 | * @param string $value1 logical expression to compare |
||
| 249 | * @param string $value2 logical expression to compare with |
||
| 250 | * |
||
| 251 | * @return string logical expression |
||
| 252 | */ |
||
| 253 | public function eq($value1, $value2) |
||
| 257 | |||
| 258 | /** |
||
| 259 | * Returns the SQL to check if two values are unequal. |
||
| 260 | * |
||
| 261 | * Example: |
||
| 262 | * <code> |
||
| 263 | * $q = $dbHandler->createSelectQuery(); |
||
| 264 | * $q->select( '*' )->from( 'table' ) |
||
| 265 | * ->where( $q->expr->neq( 'id', $q->bindValue( 1 ) ) ); |
||
| 266 | * </code> |
||
| 267 | * |
||
| 268 | * @param string $value1 logical expression to compare |
||
| 269 | * @param string $value2 logical expression to compare with |
||
| 270 | * |
||
| 271 | * @return string logical expression |
||
| 272 | */ |
||
| 273 | public function neq($value1, $value2) |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Returns the SQL to check if one value is greater than another value. |
||
| 280 | * |
||
| 281 | * Example: |
||
| 282 | * <code> |
||
| 283 | * $q = $dbHandler->createSelectQuery(); |
||
| 284 | * $q->select( '*' )->from( 'table' ) |
||
| 285 | * ->where( $q->expr->gt( 'id', $q->bindValue( 1 ) ) ); |
||
| 286 | * </code> |
||
| 287 | * |
||
| 288 | * @param string $value1 logical expression to compare |
||
| 289 | * @param string $value2 logical expression to compare with |
||
| 290 | * |
||
| 291 | * @return string logical expression |
||
| 292 | */ |
||
| 293 | public function gt($value1, $value2) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Returns the SQL to check if one value is greater than or equal to |
||
| 300 | * another value. |
||
| 301 | * |
||
| 302 | * Example: |
||
| 303 | * <code> |
||
| 304 | * $q = $dbHandler->createSelectQuery(); |
||
| 305 | * $q->select( '*' )->from( 'table' ) |
||
| 306 | * ->where( $q->expr->gte( 'id', $q->bindValue( 1 ) ) ); |
||
| 307 | * </code> |
||
| 308 | * |
||
| 309 | * @param string $value1 logical expression to compare |
||
| 310 | * @param string $value2 logical expression to compare with |
||
| 311 | * |
||
| 312 | * @return string logical expression |
||
| 313 | */ |
||
| 314 | public function gte($value1, $value2) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Returns the SQL to check if one value is less than another value. |
||
| 321 | * |
||
| 322 | * Example: |
||
| 323 | * <code> |
||
| 324 | * $q = $dbHandler->createSelectQuery(); |
||
| 325 | * $q->select( '*' )->from( 'table' ) |
||
| 326 | * ->where( $q->expr->lt( 'id', $q->bindValue( 1 ) ) ); |
||
| 327 | * </code> |
||
| 328 | * |
||
| 329 | * @param string $value1 logical expression to compare |
||
| 330 | * @param string $value2 logical expression to compare with |
||
| 331 | * |
||
| 332 | * @return string logical expression |
||
| 333 | */ |
||
| 334 | public function lt($value1, $value2) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Returns the SQL to check if one value is less than or equal to |
||
| 341 | * another value. |
||
| 342 | * |
||
| 343 | * Example: |
||
| 344 | * <code> |
||
| 345 | * $q = $dbHandler->createSelectQuery(); |
||
| 346 | * $q->select( '*' )->from( 'table' ) |
||
| 347 | * ->where( $q->expr->lte( 'id', $q->bindValue( 1 ) ) ); |
||
| 348 | * </code> |
||
| 349 | * |
||
| 350 | * @param string $value1 logical expression to compare |
||
| 351 | * @param string $value2 logical expression to compare with |
||
| 352 | * |
||
| 353 | * @return string logical expression |
||
| 354 | */ |
||
| 355 | public function lte($value1, $value2) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Returns the SQL to check if a value is one in a set of |
||
| 362 | * given values.. |
||
| 363 | * |
||
| 364 | * in() accepts an arbitrary number of parameters. The first parameter |
||
| 365 | * must always specify the value that should be matched against. Successive |
||
| 366 | * parameters must contain a logical expression or an array with logical |
||
| 367 | * expressions. These expressions will be matched against the first |
||
| 368 | * parameter. |
||
| 369 | * |
||
| 370 | * Example: |
||
| 371 | * <code> |
||
| 372 | * $q->select( '*' )->from( 'table' ) |
||
| 373 | * ->where( $q->expr->in( 'id', 1, 2, 3 ) ); |
||
| 374 | * </code> |
||
| 375 | * |
||
| 376 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with less than two |
||
| 377 | * parameters. |
||
| 378 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if the 2nd parameter is an |
||
| 379 | * empty array. |
||
| 380 | * |
||
| 381 | * @param string $column the value that should be matched against |
||
| 382 | * @param string|array(string) $... values that will be matched against $column |
||
| 383 | * |
||
| 384 | * @return string logical expression |
||
| 385 | */ |
||
| 386 | public function in($column) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Returns SQL that checks if a expression is null. |
||
| 428 | * |
||
| 429 | * Example: |
||
| 430 | * <code> |
||
| 431 | * $q = $dbHandler->createSelectQuery(); |
||
| 432 | * $q->select( '*' )->from( 'table' ) |
||
| 433 | * ->where( $q->expr->isNull( 'id' ) ); |
||
| 434 | * </code> |
||
| 435 | * |
||
| 436 | * @param string $expression the expression that should be compared to null |
||
| 437 | * |
||
| 438 | * @return string logical expression |
||
| 439 | */ |
||
| 440 | public function isNull($expression) |
||
| 444 | |||
| 445 | /** |
||
| 446 | * Returns SQL that checks if an expression evaluates to a value between |
||
| 447 | * two values. |
||
| 448 | * |
||
| 449 | * The parameter $expression is checked if it is between $value1 and $value2. |
||
| 450 | * |
||
| 451 | * Note: There is a slight difference in the way BETWEEN works on some databases. |
||
| 452 | * http://www.w3schools.com/sql/sql_between.asp. If you want complete database |
||
| 453 | * independence you should avoid using between(). |
||
| 454 | * |
||
| 455 | * Example: |
||
| 456 | * <code> |
||
| 457 | * $q = $dbHandler->createSelectQuery(); |
||
| 458 | * $q->select( '*' )->from( 'table' ) |
||
| 459 | * ->where( $q->expr->between( 'id', $q->bindValue( 1 ), $q->bindValue( 5 ) ) ); |
||
| 460 | * </code> |
||
| 461 | * |
||
| 462 | * @param string $expression the value to compare to |
||
| 463 | * @param string $value1 the lower value to compare with |
||
| 464 | * @param string $value2 the higher value to compare with |
||
| 465 | * |
||
| 466 | * @return string logical expression |
||
| 467 | */ |
||
| 468 | public function between($expression, $value1, $value2) |
||
| 472 | |||
| 473 | /** |
||
| 474 | * Match a partial string in a column. |
||
| 475 | * |
||
| 476 | * Like will look for the pattern in the column given. Like accepts |
||
| 477 | * the wildcards '_' matching a single character and '%' matching |
||
| 478 | * any number of characters. |
||
| 479 | * |
||
| 480 | * @param string $expression the name of the expression to match on |
||
| 481 | * @param string $pattern the pattern to match with. |
||
| 482 | */ |
||
| 483 | public function like($expression, $pattern) |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Returns the average value of a column. |
||
| 490 | * |
||
| 491 | * @param string $column the column to use |
||
| 492 | * |
||
| 493 | * @return string |
||
| 494 | */ |
||
| 495 | public function avg($column) |
||
| 499 | |||
| 500 | /** |
||
| 501 | * Returns the number of rows (without a NULL value) of a column. |
||
| 502 | * |
||
| 503 | * If a '*' is used instead of a column the number of selected rows |
||
| 504 | * is returned. |
||
| 505 | * |
||
| 506 | * @param string $column the column to use |
||
| 507 | * |
||
| 508 | * @return string |
||
| 509 | */ |
||
| 510 | public function count($column) |
||
| 514 | |||
| 515 | /** |
||
| 516 | * Returns the highest value of a column. |
||
| 517 | * |
||
| 518 | * @param string $column the column to use |
||
| 519 | * |
||
| 520 | * @return string |
||
| 521 | */ |
||
| 522 | public function max($column) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * Returns the lowest value of a column. |
||
| 529 | * |
||
| 530 | * @param string $column the column to use |
||
| 531 | * |
||
| 532 | * @return string |
||
| 533 | */ |
||
| 534 | public function min($column) |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Returns the total sum of a column. |
||
| 541 | * |
||
| 542 | * @param string $column the column to use |
||
| 543 | * |
||
| 544 | * @return string |
||
| 545 | */ |
||
| 546 | public function sum($column) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Returns the length of text field $column. |
||
| 553 | * |
||
| 554 | * @param string $column |
||
| 555 | * |
||
| 556 | * @return string |
||
| 557 | */ |
||
| 558 | public function length($column) |
||
| 562 | |||
| 563 | /** |
||
| 564 | * Rounds a numeric field to the number of decimals specified. |
||
| 565 | * |
||
| 566 | * @param string $column |
||
| 567 | * @param int $decimals |
||
| 568 | * |
||
| 569 | * @return string |
||
| 570 | */ |
||
| 571 | public function round($column, $decimals) |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Returns the remainder of the division operation |
||
| 578 | * $expression1 / $expression2. |
||
| 579 | * |
||
| 580 | * @param string $expression1 |
||
| 581 | * @param string $expression2 |
||
| 582 | * |
||
| 583 | * @return string |
||
| 584 | */ |
||
| 585 | public function mod($expression1, $expression2) |
||
| 589 | |||
| 590 | /** |
||
| 591 | * Returns the current system date and time in the database internal |
||
| 592 | * format. |
||
| 593 | * |
||
| 594 | * @return string |
||
| 595 | */ |
||
| 596 | public function now() |
||
| 600 | |||
| 601 | /** |
||
| 602 | * Returns part of a string. |
||
| 603 | * |
||
| 604 | * Note: Not SQL92, but common functionality. |
||
| 605 | * |
||
| 606 | * @param string $value the target $value the string or the string column. |
||
| 607 | * @param int $from extract from this characeter. |
||
| 608 | * @param int $len extract this amount of characters. |
||
| 609 | * |
||
| 610 | * @return string sql that extracts part of a string. |
||
| 611 | */ |
||
| 612 | public function subString($value, $from, $len = null) |
||
| 616 | |||
| 617 | /** |
||
| 618 | * Returns a series of strings concatinated. |
||
| 619 | * |
||
| 620 | * concat() accepts an arbitrary number of parameters. Each parameter |
||
| 621 | * must contain an expression or an array with expressions. |
||
| 622 | * |
||
| 623 | * @param string|array(string) $... strings that will be concatinated. |
||
| 624 | */ |
||
| 625 | public function concat() |
||
| 631 | |||
| 632 | /** |
||
| 633 | * Returns the SQL to locate the position of the first occurrence of a substring. |
||
| 634 | * |
||
| 635 | * @param string $substr |
||
| 636 | * @param string $value |
||
| 637 | * |
||
| 638 | * @return string |
||
| 639 | */ |
||
| 640 | public function position($substr, $value) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * Returns the SQL to change all characters to lowercase. |
||
| 647 | * |
||
| 648 | * @param string $value |
||
| 649 | * |
||
| 650 | * @return string |
||
| 651 | */ |
||
| 652 | public function lower($value) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Returns the SQL to change all characters to uppercase. |
||
| 659 | * |
||
| 660 | * @param string $value |
||
| 661 | * |
||
| 662 | * @return string |
||
| 663 | */ |
||
| 664 | public function upper($value) |
||
| 668 | |||
| 669 | /** |
||
| 670 | * Returns the SQL that performs the bitwise AND on two values. |
||
| 671 | * |
||
| 672 | * @param string $value1 |
||
| 673 | * @param string $value2 |
||
| 674 | * |
||
| 675 | * @return string |
||
| 676 | */ |
||
| 677 | public function bitAnd($value1, $value2) |
||
| 681 | |||
| 682 | /** |
||
| 683 | * Returns the SQL that performs the bitwise OR on two values. |
||
| 684 | * |
||
| 685 | * @param string $value1 |
||
| 686 | * @param string $value2 |
||
| 687 | * |
||
| 688 | * @return string |
||
| 689 | */ |
||
| 690 | public function bitOr($value1, $value2) |
||
| 694 | |||
| 695 | /** |
||
| 696 | * Returns a searched CASE statement. |
||
| 697 | * |
||
| 698 | * Accepts an arbitrary number of parameters. |
||
| 699 | * The first parameter (array) must always be specified, the last |
||
| 700 | * parameter (string) specifies the ELSE result. |
||
| 701 | * |
||
| 702 | * Example: |
||
| 703 | * <code> |
||
| 704 | * $q = $dbHandler->createSelectQuery(); |
||
| 705 | * $q->select( |
||
| 706 | * $q->expr->searchedCase( |
||
| 707 | * array( $q->expr->gte( 'column1', 20 ), 'column1' ) |
||
| 708 | * , array( $q->expr->gte( 'column2', 50 ), 'column2' ) |
||
| 709 | * , 'column3' |
||
| 710 | * ) |
||
| 711 | * ) |
||
| 712 | * ->from( 'table' ); |
||
| 713 | * </code> |
||
| 714 | * |
||
| 715 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException |
||
| 716 | * |
||
| 717 | * @return string |
||
| 718 | */ |
||
| 719 | public function searchedCase() |
||
| 742 | |||
| 743 | /** |
||
| 744 | * Returns the SQL to perform the same mathematical operation over an array |
||
| 745 | * of values or expressions. |
||
| 746 | * |
||
| 747 | * basicMath() accepts an arbitrary number of parameters. Each parameter |
||
| 748 | * must contain a value or an expression or an array with values or |
||
| 749 | * expressions. |
||
| 750 | * |
||
| 751 | * @throws \eZ\Publish\Core\Persistence\Database\QueryException if called with no parameters. |
||
| 752 | * |
||
| 753 | * @param string $type the type of operation, can be '+', '-', '*' or '/'. |
||
| 754 | * @param string|array(string) $... |
||
| 755 | * |
||
| 756 | * @return string an expression |
||
| 757 | */ |
||
| 758 | private function basicMath($type) |
||
| 773 | |||
| 774 | /** |
||
| 775 | * Returns all the elements in $array as one large single dimensional array. |
||
| 776 | * |
||
| 777 | * @param array $array |
||
| 778 | * |
||
| 779 | * @return array |
||
| 780 | */ |
||
| 781 | private function arrayFlatten(array $array) |
||
| 798 | } |
||
| 799 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.