Passed
Push — master ( 76c147...6eb882 )
by El
04:25 queued 01:03
created

lib/Model.php (3 issues)

Labels
Severity
1
<?php
2
/**
3
 * PrivateBin
4
 *
5
 * a zero-knowledge paste bin
6
 *
7
 * @link      https://github.com/PrivateBin/PrivateBin
8
 * @copyright 2012 Sébastien SAUVAGE (sebsauvage.net)
9
 * @license   https://www.opensource.org/licenses/zlib-license.php The zlib/libpng License
10
 * @version   1.1.1
11
 */
12
13
namespace PrivateBin;
14
15
use PrivateBin\Model\Paste;
0 ignored issues
show
The type PrivateBin\Model\Paste was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use PrivateBin\Persistence\PurgeLimiter;
0 ignored issues
show
The type PrivateBin\Persistence\PurgeLimiter was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
18
/**
19
 * Model
20
 *
21
 * Factory of PrivateBin instance models.
22
 */
23
class Model
24
{
25
    /**
26
     * Configuration.
27
     *
28
     * @var Configuration
29
     */
30
    private $_conf;
31
32
    /**
33
     * Data storage.
34
     *
35
     * @var AbstractData
0 ignored issues
show
The type PrivateBin\AbstractData was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
36
     */
37
    private $_store = null;
38
39
    /**
40
     * Factory constructor.
41
     *
42
     * @param configuration $conf
43
     */
44 112
    public function __construct(Configuration $conf)
45
    {
46 112
        $this->_conf = $conf;
47 112
    }
48
49
    /**
50
     * Get a paste, optionally a specific instance.
51
     *
52
     * @param string $pasteId
53
     * @return Paste
54
     */
55 94
    public function getPaste($pasteId = null)
56
    {
57 94
        $paste = new Paste($this->_conf, $this->_getStore());
58 94
        if ($pasteId !== null) {
59 64
            $paste->setId($pasteId);
60
        }
61 90
        return $paste;
62
    }
63
64
    /**
65
     * Checks if a purge is necessary and triggers it if yes.
66
     */
67 29
    public function purge()
68
    {
69 29
        PurgeLimiter::setConfiguration($this->_conf);
70 29
        if (PurgeLimiter::canPurge()) {
71 1
            $this->_getStore()->purge($this->_conf->getKey('batchsize', 'purge'));
72
        }
73 29
    }
74
75
    /**
76
     * Gets, and creates if neccessary, a store object
77
     *
78
     * @return AbstractData
79
     */
80 94
    private function _getStore()
81
    {
82 94
        if ($this->_store === null) {
83 94
            $this->_store = forward_static_call(
84 94
                'PrivateBin\\Data\\' . $this->_conf->getKey('class', 'model') . '::getInstance',
85 94
                $this->_conf->getSection('model_options')
86
            );
87
        }
88 94
        return $this->_store;
89
    }
90
}
91