SimpleRequest::camelCaseToUnderScore()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
nc 1
nop 1
dl 0
loc 3
c 0
b 0
f 0
cc 1
rs 10
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