Skip to content

Commit 3d6b3bd

Browse files
authored
Merge pull request #5031 from MGatner/phpcbd
PHP Copy-Paste Detector
2 parents ffcf115 + 60d5dc8 commit 3d6b3bd

File tree

2 files changed

+43
-68
lines changed

2 files changed

+43
-68
lines changed

.github/workflows/test-phpcpd.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# When a PR is opened or a push is made, check code
2+
# for duplication with PHP Copy/Paste Detector.
3+
name: PHPCPD
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- 'develop'
9+
- '4.*'
10+
paths:
11+
- 'app/**'
12+
- 'public/**'
13+
- 'system/**'
14+
- '.github/workflows/test-phpcpd.yml'
15+
push:
16+
branches:
17+
- 'develop'
18+
- '4.*'
19+
paths:
20+
- 'app/**'
21+
- 'public/**'
22+
- 'system/**'
23+
- '.github/workflows/test-phpcpd.yml'
24+
25+
jobs:
26+
build:
27+
name: Duplicate Code Detection
28+
runs-on: ubuntu-20.04
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v2
32+
33+
- name: Setup PHP
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: '8.0'
37+
tools: phive
38+
extensions: intl, json, mbstring, xml
39+
40+
- name: Detect code duplication
41+
run: |
42+
sudo phive --no-progress install --global --trust-gpg-keys 4AA394086372C20A phpcpd
43+
phpcpd --exclude system/Test --exclude system/ThirdParty --exclude system/Database/SQLSRV/Builder.php app/ public/ system/

system/Database/SQLSRV/Builder.php

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace CodeIgniter\Database\SQLSRV;
1313

14-
use Closure;
1514
use CodeIgniter\Database\BaseBuilder;
1615
use CodeIgniter\Database\Exceptions\DatabaseException;
1716
use CodeIgniter\Database\Exceptions\DataException;
@@ -516,73 +515,6 @@ protected function compileSelect($selectOverride = false): string
516515
return $sql;
517516
}
518517

519-
/**
520-
* WHERE, HAVING
521-
*
522-
* @param mixed $key
523-
* @param mixed $value
524-
*
525-
* @return $this
526-
*/
527-
protected function whereHaving(string $qbKey, $key, $value = null, string $type = 'AND ', ?bool $escape = null)
528-
{
529-
if (! is_array($key)) {
530-
$key = [$key => $value];
531-
}
532-
533-
// If the escape value was not set will base it on the global setting
534-
if (! is_bool($escape)) {
535-
$escape = $this->db->protectIdentifiers;
536-
}
537-
538-
foreach ($key as $k => $v) {
539-
$prefix = empty($this->{$qbKey}) ? $this->groupGetType('') : $this->groupGetType($type);
540-
541-
if ($v !== null) {
542-
$op = $this->getOperator($k, true);
543-
544-
if (! empty($op)) {
545-
$k = trim($k);
546-
547-
end($op);
548-
549-
$op = trim(current($op));
550-
551-
if (substr($k, -1 * strlen($op)) === $op) {
552-
$k = rtrim(strrev(preg_replace(strrev('/' . $op . '/'), strrev(''), strrev($k), 1)));
553-
}
554-
}
555-
556-
$bind = $this->setBind($k, $v, $escape);
557-
558-
if (empty($op)) {
559-
$k .= ' =';
560-
} else {
561-
$k .= " {$op}";
562-
}
563-
564-
if ($v instanceof Closure) {
565-
$builder = $this->cleanClone();
566-
$v = '(' . str_replace("\n", ' ', $v($builder)->getCompiledSelect()) . ')';
567-
} else {
568-
$v = " :{$bind}:";
569-
}
570-
} elseif (! $this->hasOperator($k) && $qbKey !== 'QBHaving') {
571-
// value appears not to have been set, assign the test to IS NULL
572-
$k .= ' IS NULL';
573-
} elseif (preg_match('/\s*(!?=|<>|IS(?:\s+NOT)?)\s*$/i', $k, $match, PREG_OFFSET_CAPTURE)) {
574-
$k = substr($k, 0, $match[0][1]) . ($match[1][0] === '=' ? ' IS NULL' : ' IS NOT NULL');
575-
}
576-
577-
$this->{$qbKey}[] = [
578-
'condition' => $prefix . $k . $v,
579-
'escape' => $escape,
580-
];
581-
}
582-
583-
return $this;
584-
}
585-
586518
/**
587519
* Compiles the select statement based on the other functions called
588520
* and runs the query

0 commit comments

Comments
 (0)