Skip to content

Commit c691bdc

Browse files
committed
Add experiment: bulk detect method filter
1 parent e9c204f commit c691bdc

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

.phpstorm.meta.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace PHPSTORM_META {
4+
5+
expectedArguments(
6+
\Redbitcz\DebugMode\Detector::__construct(),
7+
1,
8+
\Redbitcz\DebugMode\Detector::MODE_ALL,
9+
\Redbitcz\DebugMode\Detector::MODE_ENABLER,
10+
\Redbitcz\DebugMode\Detector::MODE_COOKIE,
11+
\Redbitcz\DebugMode\Detector::MODE_ENV,
12+
\Redbitcz\DebugMode\Detector::MODE_IP
13+
);
14+
15+
expectedArguments(
16+
\Redbitcz\DebugMode\Detector::detect(),
17+
1,
18+
\Redbitcz\DebugMode\Detector::MODE_ALL,
19+
\Redbitcz\DebugMode\Detector::MODE_ENABLER,
20+
\Redbitcz\DebugMode\Detector::MODE_COOKIE,
21+
\Redbitcz\DebugMode\Detector::MODE_ENV,
22+
\Redbitcz\DebugMode\Detector::MODE_IP
23+
);
24+
}

src/Detector.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@ class Detector
1313
private const DEBUG_ENV_NAME = 'APP_DEBUG';
1414
private const DEBUG_COOKIE_NAME = 'app-debug-mode';
1515

16+
public const MODE_ENABLER = 0b0001;
17+
public const MODE_COOKIE = 0b0010;
18+
public const MODE_ENV = 0b0100;
19+
public const MODE_IP = 0b1000;
20+
public const MODE_ALL = self::MODE_ENABLER | self::MODE_COOKIE | self::MODE_ENV | self::MODE_IP;
1621

1722
/** @var Enabler */
1823
private $enabler;
24+
/** @var int */
25+
private $mode;
1926

20-
public function __construct(string $tempDir)
27+
public function __construct(string $tempDir, int $mode = self::MODE_ALL)
2128
{
2229
$this->enabler = new Enabler($tempDir);
30+
$this->mode = $mode;
2331
}
2432

2533
public function getEnabler(): Enabler
@@ -29,10 +37,10 @@ public function getEnabler(): Enabler
2937

3038
public function isDebugMode(?bool $default = false): ?bool
3139
{
32-
return $this->isDebugModeByEnabler()
33-
?? $this->isDebugModeByCookie()
34-
?? $this->isDebugModeByEnv()
35-
?? $this->isDebugModeByIp()
40+
return ($this->mode & self::MODE_ENABLER ? $this->isDebugModeByEnabler() : null)
41+
?? ($this->mode & self::MODE_COOKIE ? $this->isDebugModeByCookie() : null)
42+
?? ($this->mode & self::MODE_ENV ? $this->isDebugModeByEnv() : null)
43+
?? ($this->mode & self::MODE_IP ? $this->isDebugModeByIp() : null)
3644
?? $default;
3745
}
3846

@@ -114,9 +122,9 @@ public function isDebugModeByIp(): ?bool
114122
return $result ?: null;
115123
}
116124

117-
public static function detect(string $tempDir, ?bool $default = false): ?bool
125+
public static function detect(string $tempDir, int $mode = self::MODE_ALL, ?bool $default = false): ?bool
118126
{
119-
return (new self($tempDir))->isDebugMode($default);
127+
return (new self($tempDir, $mode))->isDebugMode($default);
120128
}
121129

122130
public static function detectProductionMode(string $tempDir, ?bool $default = false): ?bool

0 commit comments

Comments
 (0)