Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 216a885

Browse files
committed
Merge pull request #173 from samsonasik/substr-strpos
change substr with strpos/stripos when possible
2 parents 2f426da + 8ae461c commit 216a885

File tree

7 files changed

+8
-12
lines changed

7 files changed

+8
-12
lines changed

src/Pattern/PatternOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class PatternOptions extends AbstractOptions
152152
public function __construct($options = null)
153153
{
154154
// disable file/directory permissions by default on windows systems
155-
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
155+
if (stripos(PHP_OS, 'WIN') === 0) {
156156
$this->filePermission = false;
157157
$this->dirPermission = false;
158158
}

src/Storage/Adapter/Dba.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ public function clearByNamespace($namespace)
220220
}
221221

222222
$prefix = $namespace . $this->getOptions()->getNamespaceSeparator();
223-
$prefixl = strlen($prefix);
224223
$result = true;
225224

226225
$this->_open();
@@ -230,7 +229,7 @@ public function clearByNamespace($namespace)
230229
$recheck = false;
231230
$internalKey = dba_firstkey($this->handle);
232231
while ($internalKey !== false && $internalKey !== null) {
233-
if (substr($internalKey, 0, $prefixl) === $prefix) {
232+
if (strpos($internalKey, $prefix) === 0) {
234233
$result = dba_delete($internalKey, $this->handle) && $result;
235234
}
236235

@@ -259,7 +258,6 @@ public function clearByPrefix($prefix)
259258
$options = $this->getOptions();
260259
$namespace = $options->getNamespace();
261260
$prefix = ($namespace === '') ? '' : $namespace . $options->getNamespaceSeparator() . $prefix;
262-
$prefixL = strlen($prefix);
263261
$result = true;
264262

265263
$this->_open();
@@ -269,7 +267,7 @@ public function clearByPrefix($prefix)
269267
$recheck = false;
270268
$internalKey = dba_firstkey($this->handle);
271269
while ($internalKey !== false && $internalKey !== null) {
272-
if (substr($internalKey, 0, $prefixL) === $prefix) {
270+
if (strpos($internalKey, $prefix) === 0) {
273271
$result = dba_delete($internalKey, $this->handle) && $result;
274272
$recheck = true;
275273
}

src/Storage/Adapter/FilesystemOptions.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class FilesystemOptions extends AdapterOptions
119119
public function __construct($options = null)
120120
{
121121
// disable file/directory permissions by default on windows systems
122-
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
122+
if (stripos(PHP_OS, 'WIN') === 0) {
123123
$this->filePermission = false;
124124
$this->dirPermission = false;
125125
}

src/Storage/Adapter/MemcachedResourceManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public function getLibOptions($id)
332332
$reflection = new ReflectionClass('Memcached');
333333
$constants = $reflection->getConstants();
334334
foreach ($constants as $constName => $constValue) {
335-
if (substr($constName, 0, 4) == 'OPT_') {
335+
if (strpos($constName, 'OPT_') === 0) {
336336
$libOptions[$constValue] = $resource->getOption($constValue);
337337
}
338338
}

src/Storage/Adapter/Memory.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,9 @@ public function clearByPrefix($prefix)
203203
return true;
204204
}
205205

206-
$prefixL = strlen($prefix);
207206
$data = & $this->data[$ns];
208207
foreach ($data as $key => & $item) {
209-
if (substr($key, 0, $prefixL) === $prefix) {
208+
if (strpos($key, $prefix) === 0) {
210209
unset($data[$key]);
211210
}
212211
}

src/Storage/Adapter/RedisResourceManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ public function getLibOptions($id)
492492
$reflection = new ReflectionClass('Redis');
493493
$constants = $reflection->getConstants();
494494
foreach ($constants as $constName => $constValue) {
495-
if (substr($constName, 0, 4) == 'OPT_') {
495+
if (strpos($constName, 'OPT_') === 0) {
496496
$libOptions[$constValue] = $resource['resource']->getOption($constValue);
497497
}
498498
}

src/Storage/Adapter/Session.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ public function clearByPrefix($prefix)
123123
}
124124

125125
$data = $cntr->offsetGet($ns);
126-
$prefixL = strlen($prefix);
127126
foreach ($data as $key => & $item) {
128-
if (substr($key, 0, $prefixL) === $prefix) {
127+
if (strpos($key, $prefix) === 0) {
129128
unset($data[$key]);
130129
}
131130
}

0 commit comments

Comments
 (0)