IpcKeyTrait::generateIpcKey()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.2
cc 4
eloc 6
nc 3
nop 2
1
<?php
2
/**
3
 * Process Library
4
 * @author Tao <[email protected]>
5
 */
6
namespace Slince\Process\SystemV;
7
8
use Slince\Process\Exception\RuntimeException;
9
10
trait IpcKeyTrait
11
{
12
    /**
13
     * Generates the ipc key from an existing file and a project identifier
14
     * @param string|int $pathname
15
     * @param string $projectId
16
     * @return int
17
     */
18
    public function generateIpcKey($pathname, $projectId = 'p')
19
    {
20
        if (is_numeric($pathname)) {
21
            return $pathname;
22
        }
23
        if (!file_exists($pathname) && !touch($pathname)) {
24
            throw new RuntimeException(sprintf("Cannot create the files [%s]", $pathname));
25
        }
26
        return ftok($pathname, $projectId);
27
    }
28
}
29