Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php  | 
            ||
| 12 | class Builder extends AbstractBuilder implements Fluent  | 
            ||
| 13 | { | 
            ||
| 14 | use Traits\Fields;  | 
            ||
| 15 | use Traits\Dates;  | 
            ||
| 16 | use Traits\Aliases;  | 
            ||
| 17 | use Traits\Relations;  | 
            ||
| 18 | use Traits\Macroable;  | 
            ||
| 19 | use Traits\Queueable;  | 
            ||
| 20 | |||
| 21 | /**  | 
            ||
| 22 | * @param string|callable $name  | 
            ||
| 23 | * @param callable|null $callback  | 
            ||
| 24 | *  | 
            ||
| 25 | * @return Table  | 
            ||
| 26 | */  | 
            ||
| 27 | 4 | public function table($name, callable $callback = null)  | 
            |
| 45 | |||
| 46 | /**  | 
            ||
| 47 | * @param callable|null $callback  | 
            ||
| 48 | *  | 
            ||
| 49 | * @return Entity  | 
            ||
| 50 | */  | 
            ||
| 51 | 3 | public function entity(callable $callback = null)  | 
            |
| 63 | |||
| 64 | /**  | 
            ||
| 65 | * @param string $type  | 
            ||
| 66 | * @param callable|null $callback  | 
            ||
| 67 | *  | 
            ||
| 68 | * @return Inheritance\Inheritance  | 
            ||
| 69 | */  | 
            ||
| 70 | 3 | public function inheritance($type, callable $callback = null)  | 
            |
| 80 | |||
| 81 | /**  | 
            ||
| 82 | * @param callable|null $callback  | 
            ||
| 83 | *  | 
            ||
| 84 | * @return Inheritance\Inheritance  | 
            ||
| 85 | */  | 
            ||
| 86 | 1 | public function singleTableInheritance(callable $callback = null)  | 
            |
| 90 | |||
| 91 | /**  | 
            ||
| 92 | * @param callable|null $callback  | 
            ||
| 93 | *  | 
            ||
| 94 | * @return Inheritance\Inheritance  | 
            ||
| 95 | */  | 
            ||
| 96 | 1 | public function joinedTableInheritance(callable $callback = null)  | 
            |
| 100 | |||
| 101 | /**  | 
            ||
| 102 | * @param array|string $columns  | 
            ||
| 103 | *  | 
            ||
| 104 | * @return Index  | 
            ||
| 105 | */  | 
            ||
| 106 | 3 | View Code Duplication | public function index($columns)  | 
            
| 119 | |||
| 120 | /**  | 
            ||
| 121 | * @param array|string $fields  | 
            ||
| 122 | *  | 
            ||
| 123 | * @return Primary  | 
            ||
| 124 | */  | 
            ||
| 125 | 3 | View Code Duplication | public function primary($fields)  | 
            
| 138 | |||
| 139 | /**  | 
            ||
| 140 | * @param array|string $columns  | 
            ||
| 141 | *  | 
            ||
| 142 | * @return UniqueConstraint  | 
            ||
| 143 | */  | 
            ||
| 144 | 3 | View Code Duplication | public function unique($columns)  | 
            
| 157 | |||
| 158 | /**  | 
            ||
| 159 | * @param string $embeddable  | 
            ||
| 160 | * @param string|null $field  | 
            ||
| 161 | * @param callable|null $callback  | 
            ||
| 162 | *  | 
            ||
| 163 | * @return Embedded  | 
            ||
| 164 | */  | 
            ||
| 165 | 2 | public function embed($embeddable, $field = null, callable $callback = null)  | 
            |
| 178 | |||
| 179 | /**  | 
            ||
| 180 | * @param string $name  | 
            ||
| 181 | * @param callable $callback  | 
            ||
| 182 | *  | 
            ||
| 183 | * @return Overrides\Override  | 
            ||
| 184 | */  | 
            ||
| 185 | 3 | public function override($name, callable $callback)  | 
            |
| 198 | |||
| 199 | /**  | 
            ||
| 200 | * @param callable|null $callback  | 
            ||
| 201 | *  | 
            ||
| 202 | * @return LifecycleEvents  | 
            ||
| 203 | */  | 
            ||
| 204 | 2 | public function events(callable $callback = null)  | 
            |
| 212 | |||
| 213 | /**  | 
            ||
| 214 | * @return bool  | 
            ||
| 215 | */  | 
            ||
| 216 | 14 | public function isEmbeddedClass()  | 
            |
| 220 | |||
| 221 | /**  | 
            ||
| 222 | * @param string $method  | 
            ||
| 223 | * @param array $params  | 
            ||
| 224 | *  | 
            ||
| 225 | * @return mixed  | 
            ||
| 226 | */  | 
            ||
| 227 | 7 | public function __call($method, $params)  | 
            |
| 240 | |||
| 241 | /**  | 
            ||
| 242 | * @param string $message  | 
            ||
| 243 | * @throws LogicException  | 
            ||
| 244 | */  | 
            ||
| 245 | 14 | protected function disallowInEmbeddedClasses($message = "")  | 
            |
| 251 | }  | 
            ||
| 252 |