Skip to content

PHP Copy-Paste Detector #5031

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/test-phpcpd.yml
Original file line number Diff line number Diff line change
@@ -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/
68 changes: 0 additions & 68 deletions system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace CodeIgniter\Database\SQLSRV;

use Closure;
use CodeIgniter\Database\BaseBuilder;
use CodeIgniter\Database\Exceptions\DatabaseException;
use CodeIgniter\Database\Exceptions\DataException;
Expand Down Expand Up @@ -516,73 +515,6 @@ protected function compileSelect($selectOverride = false): string
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
Expand Down