Naming::getUniqueKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Joli\JoliCi;
4
5
use Behat\Transliterator\Transliterator;
6
7
class Naming
8
{
9
    /**
10
     * Return a translitared name for a project
11
     *
12
     * @param string $projectPath Project directory
13
     *
14
     * @return string
15
     */
16
    public function getProjectName($projectPath)
17
    {
18
        $project = basename(realpath($projectPath));
19
        $project = Transliterator::transliterate($project, '-');
20
21
        return $project;
22
    }
23
24
    /**
25
     * Generate a unique key for a list of parameters, with same parameters
26
     * the key must not change (no random stuff) and the order does not matter
27
     *
28
     * @param array $parameters
29
     *
30
     * @return integer
31
     */
32
    public function getUniqueKey($parameters = array())
33
    {
34
        // First ordering parameters
35
        ksort($parameters);
36
37
        // Return a hash of the serialzed parameters
38
        return crc32(serialize($parameters));
39
    }
40
}
41