Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / mikey179 / vfsStream / src / main / php / org / bovigo / vfs / Quota.php
1 <?php
2 /**
3  * This file is part of vfsStream.
4  *
5  * For the full copyright and license information, please view the LICENSE
6  * file that was distributed with this source code.
7  *
8  * @package  org\bovigo\vfs
9  */
10 namespace org\bovigo\vfs;
11 /**
12  * Represents a quota for disk space.
13  *
14  * @since     1.1.0
15  * @internal
16  */
17 class Quota
18 {
19     /**
20      * unlimited quota
21      */
22     const UNLIMITED   = -1;
23     /**
24      * quota in bytes
25      *
26      * A value of -1 is treated as unlimited.
27      *
28      * @type  int
29      */
30     private $amount;
31
32     /**
33      * constructor
34      *
35      * @param  int  $amount  quota in bytes
36      */
37     public function __construct($amount)
38     {
39         $this->amount = $amount;
40     }
41
42     /**
43      * create with unlimited space
44      *
45      * @return  Quota
46      */
47     public static function unlimited()
48     {
49         return new self(self::UNLIMITED);
50     }
51
52     /**
53      * checks if a quota is set
54      *
55      * @return  bool
56      */
57     public function isLimited()
58     {
59         return self::UNLIMITED < $this->amount;
60     }
61
62     /**
63      * checks if given used space exceeda quota limit
64      *
65      *
66      * @param     int   $usedSpace
67      * @return    int
68      */
69     public function spaceLeft($usedSpace)
70     {
71         if (self::UNLIMITED === $this->amount) {
72             return $usedSpace;
73         }
74
75         if ($usedSpace >= $this->amount) {
76             return 0;
77         }
78
79         $spaceLeft = $this->amount - $usedSpace;
80         if (0 >= $spaceLeft) {
81             return 0;
82         }
83
84         return $spaceLeft;
85     }
86 }