| Conditions | 2 |
| Paths | 2 |
| Total Lines | 89 |
| Code Lines | 33 |
| 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 |
||
| 20 | protected function setUp() |
||
| 21 | { |
||
| 22 | if( \TestHelperMw::getConfig()->get( 'resource/db/adapter', false ) !== 'mysql' ) { |
||
| 23 | $this->markTestSkipped( 'No MySQL database configured' ); |
||
| 24 | } |
||
| 25 | |||
| 26 | |||
| 27 | $this->config = array( 'siteid' => 1 ); |
||
| 28 | |||
| 29 | $this->config['search'] = array( |
||
| 30 | 'cache.id' => array( 'label' => 'Cache ID', 'code' => 'cache.id', 'internalcode' => 'id', 'type' => 'string', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ), |
||
| 31 | 'cache.siteid' => array( 'label' => 'Cache site ID', 'code' => 'cache.siteid', 'internalcode' => 'siteid', 'type' => 'integer', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_INT ), |
||
| 32 | 'cache.value' => array( 'label' => 'Cached value', 'code' => 'cache.value', 'internalcode' => 'value', 'type' => 'string', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ), |
||
| 33 | 'cache.expire' => array( 'label' => 'Cache expiration date', 'code' => 'cache.expire', 'internalcode' => 'expire', 'type' => 'datetime', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ), |
||
| 34 | 'cache.tag.name' => array( 'label' => 'Cache tag name', 'code' => 'cache.tag.name', 'internalcode' => 'tname', 'type' => 'string', 'internaltype' => \Aimeos\MW\DB\Statement\Base::PARAM_STR ), |
||
| 35 | ); |
||
| 36 | |||
| 37 | $this->config['sql'] = array( |
||
| 38 | 'delete' => ' |
||
| 39 | DELETE FROM "mw_cache_test" WHERE "siteid" = ? AND :cond |
||
| 40 | ', |
||
| 41 | 'deletebytag' => ' |
||
| 42 | DELETE FROM "mw_cache_test" WHERE "siteid" = ? AND id IN ( |
||
| 43 | SELECT "tid" FROM "mw_cache_tag_test" WHERE "tsiteid" = ? AND :cond |
||
| 44 | ) |
||
| 45 | ', |
||
| 46 | 'get' => ' |
||
| 47 | SELECT "id", "value", "expire" FROM "mw_cache_test" WHERE "siteid" = ? AND :cond |
||
| 48 | ', |
||
| 49 | 'getbytag' => ' |
||
| 50 | SELECT "id", "value", "expire" FROM "mw_cache_test" |
||
| 51 | JOIN "mw_cache_tag_test" ON "tid" = "id" |
||
| 52 | WHERE siteid = ? AND tsiteid = ? AND :cond |
||
| 53 | ', |
||
| 54 | 'set' => ' |
||
| 55 | REPLACE INTO "mw_cache_test" ( "id", "siteid", "expire", "value" ) VALUES ( ?, ?, ?, ? ) |
||
| 56 | ', |
||
| 57 | 'settag' => ' |
||
| 58 | REPLACE INTO "mw_cache_tag_test" ( "tid", "tsiteid", "tname" ) VALUES :tuples |
||
| 59 | ', |
||
| 60 | ); |
||
| 61 | |||
| 62 | |||
| 63 | $this->dbm = \TestHelperMw::getDBManager(); |
||
| 64 | $conn = $this->dbm->acquire(); |
||
| 65 | |||
| 66 | |||
| 67 | $sql = 'DROP TABLE IF EXISTS "mw_cache_tag_test"'; |
||
| 68 | $conn->create( $sql )->execute()->finish(); |
||
| 69 | |||
| 70 | $sql = 'DROP TABLE IF EXISTS "mw_cache_test"'; |
||
| 71 | $conn->create( $sql )->execute()->finish(); |
||
| 72 | |||
| 73 | $sql = ' |
||
| 74 | CREATE TABLE IF NOT EXISTS "mw_cache_test" ( |
||
| 75 | "id" VARCHAR(255) NOT NULL, |
||
| 76 | "siteid" INTEGER NULL, |
||
| 77 | "expire" DATETIME NULL, |
||
| 78 | "value" MEDIUMTEXT NOT NULL, |
||
| 79 | KEY ("expire"), |
||
| 80 | CONSTRAINT UNIQUE KEY ("id", "siteid") |
||
| 81 | ); |
||
| 82 | '; |
||
| 83 | $conn->create( $sql )->execute()->finish(); |
||
| 84 | |||
| 85 | $sql = ' |
||
| 86 | CREATE TABLE IF NOT EXISTS "mw_cache_tag_test" ( |
||
| 87 | "tid" VARCHAR(255) NOT NULL, |
||
| 88 | "tsiteid" INTEGER NULL, |
||
| 89 | "tname" VARCHAR(255) NOT NULL, |
||
| 90 | CONSTRAINT UNIQUE ("tid", "tsiteid", "tname"), |
||
| 91 | CONSTRAINT FOREIGN KEY ("tid") REFERENCES "mw_cache_test" ("id") ON DELETE CASCADE |
||
| 92 | ); |
||
| 93 | '; |
||
| 94 | $conn->create( $sql )->execute()->finish(); |
||
| 95 | |||
| 96 | |||
| 97 | $sql = 'INSERT INTO "mw_cache_test" ("id", "siteid", "expire", "value") VALUES (\'t:1\', 1, NULL, \'test 1\')'; |
||
| 98 | $conn->create( $sql )->execute()->finish(); |
||
| 99 | |||
| 100 | $sql = 'INSERT INTO "mw_cache_tag_test" ("tid", "tsiteid", "tname") VALUES (\'t:1\', 1, \'tag:1\')'; |
||
| 101 | $conn->create( $sql )->execute()->finish(); |
||
| 102 | |||
| 103 | |||
| 104 | $this->dbm->release( $conn ); |
||
| 105 | |||
| 106 | |||
| 107 | $this->object = new \Aimeos\MW\Cache\Mysql( $this->config, $this->dbm ); |
||
| 108 | } |
||
| 109 | |||
| 159 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: