Code Duplication    Length = 44-44 lines in 2 locations

Alpha/Model/ActiveRecordProviderMySQL.php 1 location

@@ 1776-1819 (lines=44) @@
1773
     *
1774
     * @see Alpha\Model\ActiveRecordProviderInterface::checkBOTableExists()
1775
     */
1776
    public static function checkBOTableExists($BOClassName, $checkHistoryTable = false)
1777
    {
1778
        if (self::$logger == null) {
1779
            self::$logger = new Logger('ActiveRecordProviderMySQL');
1780
        }
1781
        self::$logger->debug('>>checkBOTableExists(BOClassName=['.$BOClassName.'], checkHistoryTable=['.$checkHistoryTable.'])');
1782
1783
        if (!class_exists($BOClassName)) {
1784
            throw new IllegalArguementException('The classname provided ['.$checkHistoryTable.'] is not defined!');
1785
        }
1786
1787
        $tableName = $BOClassName::TABLE_NAME;
1788
1789
        if (empty($tableName)) {
1790
            $tableName = mb_substr($BOClassName, 0, mb_strpos($BOClassName, '_'));
1791
        }
1792
1793
        if ($checkHistoryTable) {
1794
            $tableName .= '_history';
1795
        }
1796
1797
        $tableExists = false;
1798
1799
        $sqlQuery = 'SHOW TABLES;';
1800
1801
        $result = self::getConnection()->query($sqlQuery);
1802
1803
        while ($row = $result->fetch_array(MYSQLI_NUM)) {
1804
            if ($row[0] == $tableName) {
1805
                $tableExists = true;
1806
            }
1807
        }
1808
1809
        if ($result) {
1810
            self::$logger->debug('<<checkBOTableExists ['.($tableExists ? 'true' : 'false').']');
1811
1812
            return $tableExists;
1813
        } else {
1814
            throw new AlphaException('Failed to access the system database correctly, error is ['.self::getConnection()->error.']');
1815
            self::$logger->debug('<<checkBOTableExists [false]');
1816
1817
            return false;
1818
        }
1819
    }
1820
1821
    /**
1822
     * (non-PHPdoc).

Alpha/Model/ActiveRecordProviderSQLite.php 1 location

@@ 1791-1834 (lines=44) @@
1788
     *
1789
     * @see Alpha\Model\ActiveRecordProviderInterface::checkBOTableExists()
1790
     */
1791
    public static function checkBOTableExists($BOClassName, $checkHistoryTable = false)
1792
    {
1793
        if (self::$logger == null) {
1794
            self::$logger = new Logger('ActiveRecordProviderSQLite');
1795
        }
1796
        self::$logger->debug('>>checkBOTableExists(BOClassName=['.$BOClassName.'], checkHistoryTable=['.$checkHistoryTable.'])');
1797
1798
        if (!class_exists($BOClassName)) {
1799
            throw new IllegalArguementException('The classname provided ['.$checkHistoryTable.'] is not defined!');
1800
        }
1801
1802
        $tableName = $BOClassName::TABLE_NAME;
1803
1804
        if (empty($tableName)) {
1805
            $tableName = mb_substr($BOClassName, 0, mb_strpos($BOClassName, '_'));
1806
        }
1807
1808
        if ($checkHistoryTable) {
1809
            $tableName .= '_history';
1810
        }
1811
1812
        $tableExists = false;
1813
1814
        $sqlQuery = 'SELECT name FROM sqlite_master WHERE type = "table";';
1815
1816
        $result = self::getConnection()->query($sqlQuery);
1817
1818
        while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
1819
            if ($row['name'] == $tableName) {
1820
                $tableExists = true;
1821
            }
1822
        }
1823
1824
        if ($result) {
1825
            self::$logger->debug('<<checkBOTableExists ['.($tableExists ? 'true' : 'false').']');
1826
1827
            return $tableExists;
1828
        } else {
1829
            throw new AlphaException('Failed to access the system database correctly, error is ['.self::getLastDatabaseError().']');
1830
            self::$logger->debug('<<checkBOTableExists [false]');
1831
1832
            return false;
1833
        }
1834
    }
1835
1836
    /**
1837
     * (non-PHPdoc).