Passed
Pull Request — master (#238)
by Théo
02:39
created

CreateTemporaryPharFile::createTemporaryPhar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Console\Command;
16
17
use DateTimeImmutable;
18
use function KevinGH\Box\FileSystem\copy;
19
20
/**
21
 * @private
22
 */
23
trait CreateTemporaryPharFile
24
{
25
    final private function createTemporaryPhar(string $file): string
26
    {
27
        if ('' === pathinfo($file, PATHINFO_EXTENSION)) {
28
            copy($file, $tmpFile = sys_get_temp_dir().'/'.(new DateTimeImmutable())->getTimestamp().$file.'.phar');
29
30
            return $tmpFile;
31
        }
32
33
        return $file;
34
    }
35
}
36