SimpleRequest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 2
A camelCaseToUnderScore() 0 3 1
1
<?php
2
3
namespace seregazhuk\React\Memcached\Protocol\Request;
4
5
use seregazhuk\React\Memcached\Protocol\Parser;
6
7
final class SimpleRequest extends Request
8
{
9
    public function __construct(string $command, array $args)
10
    {
11
        $command = $this->camelCaseToUnderScore($command);
12
        $parsedArgs = empty($args) ? '' : ' ' . implode(' ', $args);
13
        $this->command = $command . $parsedArgs . Parser::COMMAND_SEPARATOR;
14
    }
15
16
    private function camelCaseToUnderScore(string $string): string
17
    {
18
        return strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $string), '_'));
19
    }
20
}
21