Code Duplication    Length = 42-44 lines in 2 locations

Alpha/Model/ActiveRecordProviderMySQL.php 1 location

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

Alpha/Model/ActiveRecordProviderSQLite.php 1 location

@@ 1749-1790 (lines=42) @@
1746
     *
1747
     * @see Alpha\Model\ActiveRecordProviderInterface::checkBOTableExists()
1748
     */
1749
    public static function checkBOTableExists($BOClassName, $checkHistoryTable = false)
1750
    {
1751
        if (self::$logger == null) {
1752
            self::$logger = new Logger('ActiveRecordProviderSQLite');
1753
        }
1754
        self::$logger->debug('>>checkBOTableExists(BOClassName=['.$BOClassName.'], checkHistoryTable=['.$checkHistoryTable.'])');
1755
1756
        if (!class_exists($BOClassName)) {
1757
            throw new IllegalArguementException('The classname provided ['.$checkHistoryTable.'] is not defined!');
1758
        }
1759
1760
        $tableName = $BOClassName::TABLE_NAME;
1761
1762
        if (empty($tableName)) {
1763
            $tableName = mb_substr($BOClassName, 0, mb_strpos($BOClassName, '_'));
1764
        }
1765
1766
        if ($checkHistoryTable) {
1767
            $tableName .= '_history';
1768
        }
1769
1770
        $tableExists = false;
1771
1772
        $sqlQuery = 'SELECT name FROM sqlite_master WHERE type = "table";';
1773
1774
        $result = self::getConnection()->query($sqlQuery);
1775
1776
        while ($row = $result->fetchArray(SQLITE3_ASSOC)) {
1777
            if ($row['name'] == $tableName) {
1778
                $tableExists = true;
1779
            }
1780
        }
1781
1782
        if ($result) {
1783
            self::$logger->debug('<<checkBOTableExists ['.($tableExists ? 'true' : 'false').']');
1784
1785
            return $tableExists;
1786
        } else {
1787
            self::$logger->debug('<<checkBOTableExists');
1788
            throw new AlphaException('Failed to access the system database correctly, error is ['.self::getLastDatabaseError().']');
1789
        }
1790
    }
1791
1792
    /**
1793
     * (non-PHPdoc).