Code Duplication    Length = 24-25 lines in 2 locations

src/generator/Query.php 1 location

@@ 92-116 (lines=25) @@
89
     *
90
     * @param Virtual $metadata Entity metadata
91
     */
92
    protected function createMethods($metadata)
93
    {
94
        $methods = [];
95
        // TODO: Add different method generation depending on their field type
96
        // Generate Query::where() analog for specific field.
97
        foreach ($metadata->allFieldIDs as $fieldID => $fieldName) {
98
            $code = "\n\t" . '/**';
99
            $code .= "\n\t" . ' * Add '.$fieldName.'(#' . $fieldID . ') field query condition.';
100
            $code .= "\n\t" . ' * @see Generic::where()';
101
            $code .= "\n\t" . ' * @param ' . $metadata->allFieldTypes[$fieldID] . ' $value Field value';
102
            $code .= "\n\t" . ' * @param string $relation Field to value condition relation';
103
            $code .= "\n\t" . ' *';
104
            $code .= "\n\t" . ' * @return $this Chaining';
105
            $code .= "\n\t" . ' */';
106
            $code .= "\n\t" . 'public function ' . $fieldName . '($value, $relation = ArgumentInterface::EQUAL)';
107
            $code .= "\n\t" . '{';
108
            $code .= "\n\t\t" . 'return $this->where(\'' . $fieldName . '\', $value, $relation);';
109
            $code .= "\n\t" . '}';
110
111
            $methods[] = $code;
112
        }
113
114
        // Add method text to generator
115
        $this->generator->text(implode("\n", $methods));
116
    }
117
}
118
//[PHPCOMPRESSOR(remove,end)]
119

src/generator/Table.php 1 location

@@ 97-120 (lines=24) @@
94
     *
95
     * @param Virtual $metadata Entity metadata
96
     */
97
    protected function createMethods($metadata)
98
    {
99
        $methods = [];
100
        // TODO: Add different method generation depending on their field type
101
        // Generate Query::where() analog for specific field.
102
        foreach ($metadata->allFieldIDs as $fieldID => $fieldName) {
103
            $code = "\n\t" . '/**';
104
            $code .= "\n\t" . ' * Get collection of ' . $fieldName . '(#' . $fieldID . ') table column values.';
105
            $code .= "\n\t" . ' * @see \samsoncms\api\field\Table::values($fieldID)';
106
            $code .= "\n\t" . ' * @param string $relation Field to value condition relation';
107
            $code .= "\n\t" . ' *';
108
            $code .= "\n\t" . ' * @return ' . $metadata->allFieldTypes[$fieldID] . '[] ' . $fieldName . ' values collection';
109
            $code .= "\n\t" . ' */';
110
            $code .= "\n\t" . 'public function ' . $fieldName . '()';
111
            $code .= "\n\t" . '{';
112
            $code .= "\n\t\t" . 'return $this->values(' . $fieldID . ');';
113
            $code .= "\n\t" . '}';
114
115
            $methods[] = $code;
116
        }
117
118
        // Add method text to generator
119
        $this->generator->text(implode("\n", $methods));
120
    }
121
122
    /**
123
     * Class constructor generation part.