Skip to content

Commit 2d8dc93

Browse files
committed
Apply PHPCPD
1 parent 4d0110f commit 2d8dc93

File tree

2 files changed

+45
-119
lines changed

2 files changed

+45
-119
lines changed

.github/workflows/test-phpcpd.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# When a PR is opened or a push is made, check code
2+
# for duplication with PHP Copy-Paste Detector.
3+
name: Deptrac
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 --version
44+
phpcpd --exclude system/Test --exclude system/ThirdParty --exclude system/Database/SQLSRV/Builder.php app/ public/ system/

system/Database/SQLSRV/Builder.php

Lines changed: 1 addition & 119 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;
@@ -93,57 +92,7 @@ protected function _truncate(string $table): string
9392
*/
9493
public function join(string $table, string $cond, string $type = '', ?bool $escape = null)
9594
{
96-
if ($type !== '') {
97-
$type = strtoupper(trim($type));
98-
99-
if (! in_array($type, $this->joinTypes, true)) {
100-
$type = '';
101-
} else {
102-
$type .= ' ';
103-
}
104-
}
105-
106-
// Extract any aliases that might exist. We use this information
107-
// in the protectIdentifiers to know whether to add a table prefix
108-
$this->trackAliases($table);
109-
110-
if (! is_bool($escape)) {
111-
$escape = $this->db->protectIdentifiers;
112-
}
113-
114-
if (! $this->hasOperator($cond)) {
115-
$cond = ' USING (' . ($escape ? $this->db->escapeIdentifiers($cond) : $cond) . ')';
116-
} elseif ($escape === false) {
117-
$cond = ' ON ' . $cond;
118-
} else {
119-
// Split multiple conditions
120-
if (preg_match_all('/\sAND\s|\sOR\s/i', $cond, $joints, PREG_OFFSET_CAPTURE)) {
121-
$conditions = [];
122-
$joints = $joints[0];
123-
array_unshift($joints, ['', 0]);
124-
125-
for ($i = count($joints) - 1, $pos = strlen($cond); $i >= 0; $i--) {
126-
$joints[$i][1] += strlen($joints[$i][0]); // offset
127-
$conditions[$i] = substr($cond, $joints[$i][1], $pos - $joints[$i][1]);
128-
$pos = $joints[$i][1] - strlen($joints[$i][0]);
129-
$joints[$i] = $joints[$i][0];
130-
}
131-
132-
ksort($conditions);
133-
} else {
134-
$conditions = [$cond];
135-
$joints = [''];
136-
}
137-
138-
$cond = ' ON ';
139-
140-
foreach ($conditions as $i => $condition) {
141-
$operator = $this->getOperator($condition);
142-
143-
$cond .= $joints[$i];
144-
$cond .= preg_match('/(\(*)?([\[\]\w\.\'-]+)' . preg_quote($operator, '/') . '(.*)/i', $condition, $match) ? $match[1] . $this->db->protectIdentifiers($match[2]) . $operator . $this->db->protectIdentifiers($match[3]) : $condition;
145-
}
146-
}
95+
parent::join($table, $cond, $type, $escape);
14796

14897
// Do we want to escape the table name?
14998
if ($escape === true) {
@@ -516,73 +465,6 @@ protected function compileSelect($selectOverride = false): string
516465
return $sql;
517466
}
518467

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-
586468
/**
587469
* Compiles the select statement based on the other functions called
588470
* and runs the query

0 commit comments

Comments
 (0)