ackintosh /
ganesha
| 1 | <?php |
||||
| 2 | use \Ackintosh\Ganesha; |
||||
| 3 | use \Ackintosh\Ganesha\Builder; |
||||
| 4 | |||||
| 5 | require_once dirname(__DIR__) . '/vendor/autoload.php'; |
||||
| 6 | |||||
| 7 | define('SERVICE', 'example'); |
||||
| 8 | define('TIME_WINDOW', 20); |
||||
| 9 | define('FAILURE_RATE', 10); |
||||
| 10 | define('MINIMUM_REQUESTS', 10); |
||||
| 11 | define('INTERVAL_TO_HALF_OPEN', 5); |
||||
| 12 | define('SERVER_STATE_DATA', __DIR__ . '/server/state.dat'); |
||||
| 13 | define('SERVER_STATE_NORMAL', 'normal'); |
||||
| 14 | define('SERVER_STATE_ABNORMAL', 'abnormal'); |
||||
| 15 | |||||
| 16 | function buildGanesha($storage) |
||||
| 17 | { |
||||
| 18 | switch ($storage) { |
||||
| 19 | case 'redis': |
||||
| 20 | $redis = new \Redis(); |
||||
| 21 | $redis->connect(getenv('GANESHA_EXAMPLE_REDIS') ?: 'localhost'); |
||||
| 22 | $adapter = new Ackintosh\Ganesha\Storage\Adapter\Redis($redis); |
||||
| 23 | break; |
||||
| 24 | case 'memcached': |
||||
| 25 | $m = new \Memcached(); |
||||
| 26 | $m->addServer(getenv('GANESHA_EXAMPLE_MEMCACHED') ?: 'localhost', 11211); |
||||
| 27 | $adapter = new \Ackintosh\Ganesha\Storage\Adapter\Memcached($m); |
||||
| 28 | break; |
||||
| 29 | default: |
||||
| 30 | throw new \InvalidArgumentException(); |
||||
| 31 | break; |
||||
| 32 | } |
||||
| 33 | |||||
| 34 | $ganesha = Builder::build([ |
||||
| 35 | 'adapter' => $adapter, |
||||
| 36 | 'timeWindow' => TIME_WINDOW, |
||||
| 37 | 'failureRateThreshold' => FAILURE_RATE, |
||||
| 38 | 'minimumRequests' => MINIMUM_REQUESTS, |
||||
| 39 | 'intervalToHalfOpen' => INTERVAL_TO_HALF_OPEN, |
||||
| 40 | ]); |
||||
| 41 | |||||
| 42 | $messageOnTripped = <<<__EOS__ |
||||
| 43 | !!!!!!!!!!!!!!!!!!!!!!! |
||||
| 44 | !!!!!!! TRIPPED !!!!!!! |
||||
| 45 | !!!!!!!!!!!!!!!!!!!!!!! |
||||
| 46 | |||||
| 47 | __EOS__; |
||||
| 48 | $messageOnCalmedDown = <<<__EOS__ |
||||
| 49 | ======================= |
||||
| 50 | ===== CALMED DOWN ===== |
||||
| 51 | ======================= |
||||
| 52 | |||||
| 53 | __EOS__; |
||||
| 54 | |||||
| 55 | $ganesha->subscribe(function ($event, $service, $message) use ($messageOnTripped, $messageOnCalmedDown) { |
||||
|
0 ignored issues
–
show
The parameter
$service is not used and could be removed.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for parameters that have been defined for a function or method, but which are not used in the method body. Loading history...
|
|||||
| 56 | switch ($event) { |
||||
| 57 | case Ganesha::EVENT_TRIPPED: |
||||
| 58 | echo $messageOnTripped; |
||||
| 59 | break; |
||||
| 60 | case Ganesha::EVENT_CALMED_DOWN: |
||||
| 61 | echo $messageOnCalmedDown; |
||||
| 62 | break; |
||||
| 63 | default: |
||||
| 64 | break; |
||||
| 65 | } |
||||
| 66 | }); |
||||
| 67 | |||||
| 68 | return $ganesha; |
||||
| 69 | } |
||||
| 70 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.