AbstractLogFactory::createFileBuffer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
crap 1
1
<?php
2
/*
3
 * Copyright (C) 2017 by TEQneers GmbH & Co. KG
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy
6
 * of this software and associated documentation files (the "Software"), to deal
7
 * in the Software without restriction, including without limitation the rights
8
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the Software is
10
 * furnished to do so, subject to the following conditions:
11
 *
12
 * The above copyright notice and this permission notice shall be included in
13
 * all copies or substantial portions of the Software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
 * THE SOFTWARE.
22
 */
23
24
/**
25
 * Git Stream Wrapper for PHP
26
 *
27
 * @category   TQ
28
 * @package    TQ_VCS
29
 * @subpackage VCS
30
 * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG
31
 */
32
33
namespace TQ\Vcs\StreamWrapper\FileBuffer\Factory;
34
use TQ\Vcs\Buffer\FileBufferInterface;
35
use TQ\Vcs\Repository\RepositoryInterface;
36
use TQ\Vcs\StreamWrapper\FileBuffer\FactoryInterface;
37
use TQ\Vcs\Buffer\StringBuffer;
38
use TQ\Vcs\StreamWrapper\PathInformationInterface;
39
40
/**
41
 * Factory to create a log buffer
42
 *
43
 * @author     Stefan Gehrig <gehrigteqneers.de>
44
 * @category   TQ
45
 * @package    TQ_VCS
46
 * @subpackage VCS
47
 * @copyright  Copyright (C) 2018 by TEQneers GmbH & Co. KG
48
 */
49
abstract class AbstractLogFactory implements FactoryInterface
50
{
51
    /**
52
     * Returns true if this factory can handle the requested path
53
     *
54
     * @param   PathInformationInterface     $path   The path information
55
     * @param   string                       $mode   The mode used to open the file
56
     * @return  boolean                              True if this factory can handle the path
57
     */
58 50
    public function canHandle(PathInformationInterface $path, $mode)
59
    {
60 50
        return $path->hasArgument('log');
61
    }
62
63
    /**
64
     * Returns the file stream to handle the requested path
65
     *
66
     * @param   PathInformationInterface     $path   The path information
67
     * @param   string                       $mode   The mode used to open the path
68
     * @return  FileBufferInterface                  The file buffer to handle the path
69
     */
70 2
    public function createFileBuffer(PathInformationInterface $path, $mode)
71
    {
72 2
        return new StringBuffer(
73 2
            $this->createLogString(
74 2
                $path->getRepository(),
75 2
                $path->getArgument('limit'),
76 2
                $path->getArgument('skip')
77
            ),
78 2
            array(),
79 2
            'r'
80
        );
81
    }
82
83
    /**
84
     * Creates the log string to be fed into the string buffer
85
     *
86
     * @param   RepositoryInterface     $repository The repository
87
     * @param   integer|null            $limit      The maximum number of log entries returned
88
     * @param   integer|null            $skip       Number of log entries that are skipped from the beginning
89
     * @return  string
90
     */
91
    abstract protected function createLogString(RepositoryInterface $repository, $limit, $skip);
92
}
93