Conditions | 4 |
Paths | 4 |
Total Lines | 56 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
30 | public function testExecute() |
||
31 | { |
||
32 | $generator = new ChainGeneratorFactory(); |
||
33 | $generator->addFactory(new ConstantGeneratorFactory()) |
||
34 | ->addFactory(new FakerGeneratorFactory()); |
||
35 | |||
36 | $command = (new Application('Database anonymizer', '0.0.1')) |
||
37 | ->add(new AnonymizeCommand($generator)); |
||
38 | |||
39 | $commandTester = new CommandTester($command); |
||
40 | |||
41 | $commandTester->setInputs(array('y')); |
||
42 | $commandTester->execute([ |
||
43 | 'command' => $command->getName(), |
||
44 | '--config' => realpath(__DIR__.'/../../config/config.yaml'), |
||
45 | '--type' => $GLOBALS['db_type'], |
||
46 | '--host' => $GLOBALS['db_host'], |
||
47 | '--port' => $GLOBALS['db_port'], |
||
48 | '--database' => $GLOBALS['db_name'], |
||
49 | '--user' => $GLOBALS['db_username'], |
||
50 | '--password' => $GLOBALS['db_password'], |
||
51 | ]); |
||
52 | |||
53 | $connection = $this->getConnection(); |
||
54 | |||
55 | $selectSQL = $connection->createQueryBuilder() |
||
56 | ->select('email, firstname, lastname, birthdate, phone, password') |
||
57 | ->from('users') |
||
58 | ->getSQL(); |
||
59 | $selectStmt = $connection->prepare($selectSQL); |
||
60 | $selectStmt->execute(); |
||
61 | |||
62 | while ($row = $selectStmt->fetch()) { |
||
63 | $this->assertTrue(is_string($row['email'])); |
||
64 | $this->assertTrue(is_string($row['firstname'])); |
||
65 | $this->assertTrue(is_string($row['lastname'])); |
||
66 | $this->assertTrue(is_string($row['birthdate'])); |
||
67 | $this->assertTrue(is_string($row['phone']) || is_null($row['phone'])); |
||
68 | $this->assertTrue(is_string($row['password'])); |
||
69 | } |
||
70 | |||
71 | $selectSQL = $connection->createQueryBuilder() |
||
72 | ->select('address, street_address, zip_code, city, country, comment, comment, created_at') |
||
73 | ->from('orders') |
||
74 | ->getSQL(); |
||
75 | $selectStmt = $connection->prepare($selectSQL); |
||
76 | $selectStmt->execute(); |
||
77 | |||
78 | while ($row = $selectStmt->fetch()) { |
||
79 | $this->assertTrue(is_string($row['address'])); |
||
80 | $this->assertTrue(is_string($row['street_address'])); |
||
81 | $this->assertTrue(is_string($row['zip_code'])); |
||
82 | $this->assertTrue(is_string($row['city'])); |
||
83 | $this->assertTrue(is_string($row['country'])); |
||
84 | $this->assertTrue(is_string($row['comment'])); |
||
85 | $this->assertTrue(is_string($row['created_at'])); |
||
86 | } |
||
89 |