Code Duplication    Length = 11-11 lines in 2 locations

src/Util/Str.php 2 locations

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