Skip to content

Commit e92dd16

Browse files
committed
[VarDumper] code review changes
- cache memcached options and constants in static properties - change substr to strpos
1 parent 41c3bd6 commit e92dd16

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/Symfony/Component/VarDumper/Caster/MemcachedCaster.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
*/
1919
class MemcachedCaster
2020
{
21+
public static $optionConstants;
22+
public static $defaultOptions;
23+
2124
public static function castMemcached(\Memcached $c, array $a, Stub $stub, $isNested)
2225
{
2326
$a += array(
@@ -32,12 +35,12 @@ public static function castMemcached(\Memcached $c, array $a, Stub $stub, $isNes
3235

3336
public static function getMemcachedNonDefaultValueOptions(\Memcached $c)
3437
{
35-
$defaultOptions = self::discoverDefaultMemcachedOptions();
36-
$optionConstants = self::getMemcachedOptionConstants();
38+
self::$defaultOptions = self::$defaultOptions ?? self::discoverDefaultMemcachedOptions();
39+
self::$optionConstants = self::$optionConstants ?? self::getMemcachedOptionConstants();
3740

3841
$nonDefaultOptions = array();
39-
foreach ($optionConstants as $constantKey => $value) {
40-
if ($defaultOptions[$constantKey] !== $option = $c->getOption($value)) {
42+
foreach (self::$optionConstants as $constantKey => $value) {
43+
if (self::$defaultOptions[$constantKey] !== $option = $c->getOption($value)) {
4144
$nonDefaultOptions[$constantKey] = $option;
4245
}
4346
}
@@ -66,7 +69,7 @@ public static function getMemcachedOptionConstants()
6669

6770
$optionConstants = array();
6871
foreach ($reflectedMemcached->getConstants() as $constantKey => $value) {
69-
if ('OPT_' === substr($constantKey, 0, 4)) {
72+
if (0 === strpos($constantKey, 'OPT_')) {
7073
$optionConstants[$constantKey] = $value;
7174
}
7275
}

0 commit comments

Comments
 (0)