Merge pull request #5031 from MGatner/phpcbd

PHP Copy-Paste Detector
This commit is contained in:
MGatner 2021-08-30 10:56:59 -04:00 committed by GitHub
commit 3d6b3bd4a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 68 deletions

43
.github/workflows/test-phpcpd.yml vendored Normal file
View File

@ -0,0 +1,43 @@
# When a PR is opened or a push is made, check code
# for duplication with PHP Copy/Paste Detector.
name: PHPCPD
on:
pull_request:
branches:
- 'develop'
- '4.*'
paths:
- 'app/**'
- 'public/**'
- 'system/**'
- '.github/workflows/test-phpcpd.yml'
push:
branches:
- 'develop'
- '4.*'
paths:
- 'app/**'
- 'public/**'
- 'system/**'
- '.github/workflows/test-phpcpd.yml'
jobs:
build:
name: Duplicate Code Detection
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
tools: phive
extensions: intl, json, mbstring, xml
- name: Detect code duplication
run: |
sudo phive --no-progress install --global --trust-gpg-keys 4AA394086372C20A phpcpd
phpcpd --exclude system/Test --exclude system/ThirdParty --exclude system/Database/SQLSRV/Builder.php app/ public/ system/

View File

@ -11,7 +11,6 @@
namespace CodeIgniter\Database\SQLSRV;
use Closure;
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Exceptions\DataException;
@ -516,73 +515,6 @@ class Builder extends BaseBuilder
return $sql;
}
/**
* WHERE, HAVING
*
* @param mixed $key
* @param mixed $value
*
* @return $this
*/
protected function whereHaving(string $qbKey, $key, $value = null, string $type = 'AND ', ?bool $escape = null)
{
if (! is_array($key)) {
$key = [$key => $value];
}
// If the escape value was not set will base it on the global setting
if (! is_bool($escape)) {
$escape = $this->db->protectIdentifiers;
}
foreach ($key as $k => $v) {
$prefix = empty($this->{$qbKey}) ? $this->groupGetType('') : $this->groupGetType($type);
if ($v !== null) {
$op = $this->getOperator($k, true);
if (! empty($op)) {
$k = trim($k);
end($op);
$op = trim(current($op));
if (substr($k, -1 * strlen($op)) === $op) {
$k = rtrim(strrev(preg_replace(strrev('/' . $op . '/'), strrev(''), strrev($k), 1)));
}
}
$bind = $this->setBind($k, $v, $escape);
if (empty($op)) {
$k .= ' =';
} else {
$k .= " {$op}";
}
if ($v instanceof Closure) {
$builder = $this->cleanClone();
$v = '(' . str_replace("\n", ' ', $v($builder)->getCompiledSelect()) . ')';
} else {
$v = " :{$bind}:";
}
} elseif (! $this->hasOperator($k) && $qbKey !== 'QBHaving') {
// value appears not to have been set, assign the test to IS NULL
$k .= ' IS NULL';
} elseif (preg_match('/\s*(!?=|<>|IS(?:\s+NOT)?)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE)) {
$k = substr($k, 0, $match[0][1]) . ($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL');
}
$this->{$qbKey}[] = [
'condition' => $prefix . $k . $v,
'escape' => $escape,
];
}
return $this;
}
/**
* Compiles the select statement based on the other functions called
* and runs the query