GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Factory::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 4
nop 0
crap 12
1
<?php
2
/*
3
 * This file is part of the php-vfs package.
4
 *
5
 * (c) Michael Donat <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace VirtualFileSystem;
12
13
use VirtualFileSystem\Structure\Directory;
14
use VirtualFileSystem\Structure\File;
15
use VirtualFileSystem\Structure\Link;
16
use VirtualFileSystem\Structure\Node;
17
use VirtualFileSystem\Structure\Root;
18
19
/**
20
 * Factory class to encapsulate object creation.
21
 *
22
 * @author Michael Donat <[email protected]>
23
 * @package php-vfs
24
 */
25
class Factory
26
{
27
    protected $userid;
28
    protected $groupid;
29
30
    /**
31
     * Class constructor. Sets user/group to current system user/group.
32
     *
33
     * On non POSIX systems both attributes will be set to 0
34
     *
35
     */
36
    public function __construct()
37
    {
38
        $this->userid = function_exists('posix_getuid') ? posix_getuid() : 0;
39
        $this->groupid = function_exists('posix_getgid') ? posix_getgid() : 0;
40
    }
41
42
    /**
43
     * Creates Root object.
44
     *
45
     * @return Root
46
     */
47
    public function getRoot()
48
    {
49
        return $this->updateMetadata(new Root());
50
    }
51
52
    /**
53
     * Updates time and ownership of a node
54
     *
55
     * @param Node $node
56
     *
57
     * @return Node
58
     */
59
    public function updateMetadata(Node $node)
60
    {
61
        $this->updateFileTimes($node);
62
        $this->updateOwnership($node);
63
64
        return $node;
65
    }
66
67
    /**
68
     * Update file a/c/m times
69
     *
70
     * @param  Node $node
71
     * @return Node
72
     */
73
    public function updateFileTimes(Node $node)
74
    {
75
        $time = time();
76
        $node->setAccessTime($time);
77
        $node->setModificationTime($time);
78
        $node->setChangeTime($time);
79
80
        return $node;
81
    }
82
83
    /**
84
     * Sets default (current) uid/gui on object.
85
     *
86
     * @param Node $node
87
     *
88
     * @return Node
89
     */
90
    protected function updateOwnership(Node $node)
91
    {
92
        $node->chown($this->userid);
93
        $node->chgrp($this->groupid);
94
95
        return $node;
96
    }
97
98
    /**
99
     * Creates Directory object.
100
     *
101
     * @param string $basename
102
     *
103
     * @return Directory
104
     */
105
    public function getDir($basename)
106
    {
107
        return $this->updateMetadata(new Directory($basename));
108
    }
109
110
    /**
111
     * Creates File object.
112
     *
113
     * @param string $basename
114
     *
115
     * @return File
116
     */
117
    public function getFile($basename)
118
    {
119
        return $this->updateMetadata(new File($basename));
120
    }
121
122
    /**
123
     * Creates Link object.
124
     *
125
     * @param string         $basename
126
     * @param Structure\Node $destination
127
     *
128
     * @return Link
129
     */
130
    public function getLink($basename, Node $destination)
131
    {
132
        return $this->updateMetadata(new Link($basename, $destination));
133
    }
134
}
135