Code Duplication    Length = 58-61 lines in 2 locations

Alpha/Model/ActiveRecordProviderMySQL.php 1 location

@@ 2276-2336 (lines=61) @@
2273
     *
2274
     * @see Alpha\Model\ActiveRecordProviderInterface::isTableOverloaded()
2275
     */
2276
    public function isTableOverloaded()
2277
    {
2278
        self::$logger->debug('>>isTableOverloaded()');
2279
2280
        $reflection = new ReflectionClass($this->BO);
2281
        $classname = $reflection->getShortName();
2282
        $tablename = ucfirst($this->BO->getTableName());
2283
2284
        // use reflection to check to see if we are dealing with a persistent type (e.g. DEnum) which are never overloaded
2285
        $implementedInterfaces = $reflection->getInterfaces();
2286
2287
        foreach ($implementedInterfaces as $interface) {
2288
            if ($interface->name == 'Alpha\Model\Type\TypeInterface') {
2289
                self::$logger->debug('<<isTableOverloaded [false]');
2290
2291
                return false;
2292
            }
2293
        }
2294
2295
        if ($classname != $tablename) {
2296
            // loop over all BOs to see if there is one using the same table as this BO
2297
2298
            $BOclasses = ActiveRecord::getBOClassNames();
2299
2300
            foreach ($BOclasses as $BOclassName) {
2301
                $reflection = new ReflectionClass($BOclassName);
2302
                $classname = $reflection->getShortName();
2303
                if ($tablename == $classname) {
2304
                    self::$logger->debug('<<isTableOverloaded [true]');
2305
2306
                    return true;
2307
                }
2308
            }
2309
            throw new BadTableNameException('The table name ['.$tablename.'] for the class ['.$classname.'] is invalid as it does not match a BO definition in the system!');
2310
            self::$logger->debug('<<isTableOverloaded [false]');
2311
2312
            return false;
2313
        } else {
2314
            // check to see if there is already a "classname" column in the database for this BO
2315
2316
            $query = 'SHOW COLUMNS FROM '.$this->BO->getTableName();
2317
2318
            $result = self::getConnection()->query($query);
2319
2320
            if ($result) {
2321
                while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
2322
                    if ('classname' == $row['Field']) {
2323
                        self::$logger->debug('<<isTableOverloaded [true]');
2324
2325
                        return true;
2326
                    }
2327
                }
2328
            } else {
2329
                self::$logger->warn('Error during show columns ['.self::getConnection()->error.']');
2330
            }
2331
2332
            self::$logger->debug('<<isTableOverloaded [false]');
2333
2334
            return false;
2335
        }
2336
    }
2337
2338
    /**
2339
     * (non-PHPdoc).

Alpha/Model/ActiveRecordProviderSQLite.php 1 location

@@ 2191-2248 (lines=58) @@
2188
     *
2189
     * @see Alpha\Model\ActiveRecordProviderInterface::isTableOverloaded()
2190
     */
2191
    public function isTableOverloaded()
2192
    {
2193
        self::$logger->debug('>>isTableOverloaded()');
2194
2195
        $reflection = new ReflectionClass($this->BO);
2196
        $classname = $reflection->getShortName();
2197
        $tablename = ucfirst($this->BO->getTableName());
2198
2199
        // use reflection to check to see if we are dealing with a persistent type (e.g. DEnum) which are never overloaded
2200
        $implementedInterfaces = $reflection->getInterfaces();
2201
2202
        foreach ($implementedInterfaces as $interface) {
2203
            if ($interface->name == 'Alpha\Model\Type\TypeInterface') {
2204
                self::$logger->debug('<<isTableOverloaded [false]');
2205
2206
                return false;
2207
            }
2208
        }
2209
2210
        if ($classname != $tablename) {
2211
            // loop over all BOs to see if there is one using the same table as this BO
2212
2213
            $BOclasses = ActiveRecord::getBOClassNames();
2214
2215
            foreach ($BOclasses as $BOclassName) {
2216
                $reflection = new ReflectionClass($BOclassName);
2217
                $classname = $reflection->getShortName();
2218
                if ($tablename == $classname) {
2219
                    self::$logger->debug('<<isTableOverloaded [true]');
2220
2221
                    return true;
2222
                }
2223
            }
2224
            self::$logger->debug('<<isTableOverloaded');
2225
            throw new BadTableNameException('The table name ['.$tablename.'] for the class ['.$classname.'] is invalid as it does not match a BO definition in the system!');
2226
        } else {
2227
            // check to see if there is already a "classname" column in the database for this BO
2228
            $sqlQuery = 'PRAGMA table_info('.$this->BO->getTableName().')';
2229
            $result = self::getConnection()->query($sqlQuery);
2230
            $this->BO->setLastQuery($sqlQuery);
2231
2232
            if (!$result) {
2233
                self::$logger->warn('Error during pragma table info lookup ['.self::getLastDatabaseError().']');
2234
            } else {
2235
                while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
2236
                    if ('classname' == $row['name']) {
2237
                        self::$logger->debug('<<isTableOverloaded [true]');
2238
2239
                        return true;
2240
                    }
2241
                }
2242
            }
2243
2244
            self::$logger->debug('<<isTableOverloaded [false]');
2245
2246
            return false;
2247
        }
2248
    }
2249
2250
    /**
2251
     * (non-PHPdoc).