IpcKeyTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 19
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateIpcKey() 0 10 4
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