Code Duplication    Length = 11-11 lines in 2 locations

src/Util/Str.php 2 locations

@@ 113-123 (lines=11) @@
110
     * @throws \RuntimeException
111
     * @return integer
112
     */
113
    public static function toBytes($value)
114
    {
115
        if (!preg_match('#^[0-9]*[BKMGT]$#i', $value)) {
116
            throw new RuntimeException('Invalid size value');
117
        }
118
        $units  = ['B' => 0, 'K' => 1, 'M' => 2, 'G' => 3, 'T' => 4, 'P' => 5];
119
        $unit   = strtoupper(substr($value, -1));
120
        $number = intval(substr($value, 0, -1));
121
122
        return $number * pow(1024, $units[$unit]);
123
    }
124
125
    /**
126
     * Return time in seconds for a given value.
@@ 144-154 (lines=11) @@
141
     * @throws \RuntimeException
142
     * @return integer
143
     */
144
    public static function toTime($offset)
145
    {
146
        if (!preg_match('#^[1-9]+[0-9]*[SIHDWMY]$#i', $offset)) {
147
            throw new RuntimeException(sprintf('Invalid value for offset: %s', $offset));
148
        }
149
        $units  = ['S' => 1, 'I' => 60, 'H' => 3600, 'D' => 86400, 'W' => 604800, 'M' => 2678400, 'Y' => 31536000];
150
        $unit   = strtoupper(substr($offset, -1));
151
        $number = intval(substr($offset, 0, -1));
152
153
        return $number * $units[$unit];
154
    }
155
156
    /**
157
     * Pads all given strings to given length.