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 |
||
| 10 | class PodsRESTFields { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Pods object |
||
| 14 | * |
||
| 15 | * @since 2.5.6 |
||
| 16 | * |
||
| 17 | * @access protected |
||
| 18 | * |
||
| 19 | * @var Pods |
||
| 20 | */ |
||
| 21 | protected $pod; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Constructor for class |
||
| 25 | * |
||
| 26 | * @since 2.5.6 |
||
| 27 | * |
||
| 28 | * @param string|object|Pods $pod Pods object |
||
| 29 | */ |
||
| 30 | public function __construct( $pod ) { |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Set the Pods object |
||
| 46 | * |
||
| 47 | * @since 2.5.6 |
||
| 48 | * |
||
| 49 | * @access protected |
||
| 50 | * |
||
| 51 | * @param string|Pods $pod Pods object or name of Pods object |
||
| 52 | */ |
||
| 53 | private function set_pod( $pod ) { |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Add fields, based on options to REST read/write requests |
||
| 72 | * |
||
| 73 | * @since 2.5.6 |
||
| 74 | * |
||
| 75 | * @access protected |
||
| 76 | */ |
||
| 77 | protected function add_fields() { |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Register fields and their callbacks for read/write via REST |
||
| 92 | * |
||
| 93 | * @since 2.5.6 |
||
| 94 | * |
||
| 95 | * @access protected |
||
| 96 | * |
||
| 97 | * @param string $field_name Name of fields. |
||
| 98 | * @param bool|string|array $read Allowing reading? |
||
| 99 | * @param bool|string|array $write Allow writing? |
||
| 100 | */ |
||
| 101 | protected function register( $field_name, $read, $write ) { |
||
| 130 | |||
| 131 | /** |
||
| 132 | * Check if a field supports read or write via the REST API. |
||
| 133 | * |
||
| 134 | * @since 2.5.6 |
||
| 135 | * |
||
| 136 | * @param string $field_name The field name. |
||
| 137 | * @param object|Pods $pod Pods object. |
||
| 138 | * @param string $mode Are we checking read or write? |
||
| 139 | * |
||
| 140 | * @return bool If supports, true, else false. |
||
| 141 | */ |
||
| 142 | public static function field_allowed_to_extend( $field_name, $pod, $mode = 'read' ) { |
||
| 169 | |||
| 170 | } |