Test Failed
Push — develop ( 90366f...812a46 )
by Adrien
28:16
created

Root::_saveBbd()   F

Complexity

Conditions 21
Paths 17920

Size

Total Lines 78
Code Lines 48

Duplication

Lines 23
Ratio 29.49 %

Code Coverage

Tests 26
CRAP Score 66.6108

Importance

Changes 0
Metric Value
cc 21
eloc 48
nc 17920
nop 3
dl 23
loc 78
ccs 26
cts 49
cp 0.5306
crap 66.6108
rs 2.274
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Shared\OLE\PPS;
4
5
// vim: set expandtab tabstop=4 shiftwidth=4:
6
// +----------------------------------------------------------------------+
7
// | PHP Version 4                                                        |
8
// +----------------------------------------------------------------------+
9
// | Copyright (c) 1997-2002 The PHP Group                                |
10
// +----------------------------------------------------------------------+
11
// | This source file is subject to version 2.02 of the PHP license,      |
12
// | that is bundled with this package in the file LICENSE, and is        |
13
// | available at through the world-wide-web at                           |
14
// | http://www.php.net/license/2_02.txt.                                 |
15
// | If you did not receive a copy of the PHP license and are unable to   |
16
// | obtain it through the world-wide-web, please send a note to          |
17
// | [email protected] so we can mail you a copy immediately.               |
18
// +----------------------------------------------------------------------+
19
// | Author: Xavier Noguer <[email protected]>                              |
20
// | Based on OLE::Storage_Lite by Kawai, Takanori                        |
21
// +----------------------------------------------------------------------+
22
//
23
use PhpOffice\PhpSpreadsheet\Shared\OLE;
24
use PhpOffice\PhpSpreadsheet\Shared\OLE\PPS;
25
use PhpOffice\PhpSpreadsheet\Writer\Exception as WriterException;
26
27
/**
28
 * Class for creating Root PPS's for OLE containers.
29
 *
30
 * @author   Xavier Noguer <[email protected]>
31
 *
32
 * @category PhpSpreadsheet
33
 */
34
class Root extends PPS
35
{
36
    /**
37
     * Directory for temporary files.
38
     *
39
     * @var string
40
     */
41
    protected $tempDirectory;
42
43
    /**
44
     * @var resource
45
     */
46
    private $fileHandle;
47
48
    /**
49
     * @var string
50
     */
51
    private $tempFilename;
52
53
    /**
54
     * @var int
55
     */
56
    private $smallBlockSize;
57
58
    /**
59
     * @var int
60
     */
61
    private $bigBlockSize;
62
63
    /**
64
     * @param int $time_1st A timestamp
65
     * @param int $time_2nd A timestamp
66
     * @param File[] $raChild
67
     */
68 39
    public function __construct($time_1st, $time_2nd, $raChild)
69
    {
70 39
        $this->tempDirectory = \PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir();
71
72 39
        parent::__construct(null, OLE::ascToUcs('Root Entry'), OLE::OLE_PPS_TYPE_ROOT, null, null, null, $time_1st, $time_2nd, null, $raChild);
73 39
    }
74
75
    /**
76
     * Method for saving the whole OLE container (including files).
77
     * In fact, if called with an empty argument (or '-'), it saves to a
78
     * temporary file and then outputs it's contents to stdout.
79
     * If a resource pointer to a stream created by fopen() is passed
80
     * it will be used, but you have to close such stream by yourself.
81
     *
82
     * @param resource|string $filename the name of the file or stream where to save the OLE container
83
     *
84
     * @throws WriterException
85
     *
86
     * @return bool true on success
87
     */
88 39
    public function save($filename)
89
    {
90
        // Initial Setting for saving
91 39
        $this->bigBlockSize = pow(
92 39
            2,
93 39
            (isset($this->bigBlockSize)) ? self::adjust2($this->bigBlockSize) : 9
94
        );
95 39
        $this->smallBlockSize = pow(
96 39
            2,
97 39
            (isset($this->smallBlockSize)) ? self::adjust2($this->smallBlockSize) : 6
98
        );
99
100 39
        if (is_resource($filename)) {
101
            $this->fileHandle = $filename;
102 39
        } elseif ($filename == '-' || $filename == '') {
103
            if ($this->tempDirectory === null) {
104
                $this->tempDirectory = \PhpOffice\PhpSpreadsheet\Shared\File::sysGetTempDir();
105
            }
106
            $this->tempFilename = tempnam($this->tempDirectory, 'OLE_PPS_Root');
0 ignored issues
show
Documentation Bug introduced by
It seems like tempnam($this->tempDirectory, 'OLE_PPS_Root') can also be of type false. However, the property $tempFilename is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
107
            $this->fileHandle = fopen($this->tempFilename, 'w+b');
1 ignored issue
show
Documentation Bug introduced by
It seems like fopen($this->tempFilename, 'w+b') can also be of type false. However, the property $fileHandle is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
Bug introduced by
It seems like $this->tempFilename can also be of type false; however, parameter $filename of fopen() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

107
            $this->fileHandle = fopen(/** @scrutinizer ignore-type */ $this->tempFilename, 'w+b');
Loading history...
108
            if ($this->fileHandle == false) {
109
                throw new WriterException("Can't create temporary file.");
110
            }
111
        } else {
112 39
            $this->fileHandle = fopen($filename, 'wb');
113
        }
114 39
        if ($this->fileHandle == false) {
115
            throw new WriterException("Can't open $filename. It may be in use or protected.");
116
        }
117
        // Make an array of PPS's (for Save)
118 39
        $aList = [];
119 39
        PPS::_savePpsSetPnt($aList, [$this]);
120
        // calculate values for header
121 39
        list($iSBDcnt, $iBBcnt, $iPPScnt) = $this->_calcSize($aList); //, $rhInfo);
122
        // Save Header
123 39
        $this->_saveHeader($iSBDcnt, $iBBcnt, $iPPScnt);
124
125
        // Make Small Data string (write SBD)
126 39
        $this->_data = $this->_makeSmallData($aList);
127
128
        // Write BB
129 39
        $this->_saveBigData($iSBDcnt, $aList);
130
        // Write PPS
131 39
        $this->_savePps($aList);
132
        // Write Big Block Depot and BDList and Adding Header informations
133 39
        $this->_saveBbd($iSBDcnt, $iBBcnt, $iPPScnt);
134
135 39
        if (!is_resource($filename)) {
136 39
            fclose($this->fileHandle);
137
        }
138
139 39
        return true;
140
    }
141
142
    /**
143
     * Calculate some numbers.
144
     *
145
     * @param array $raList Reference to an array of PPS's
146
     *
147
     * @return float[] The array of numbers
148
     */
149 39
    public function _calcSize(&$raList)
150
    {
151
        // Calculate Basic Setting
152 39
        list($iSBDcnt, $iBBcnt, $iPPScnt) = [0, 0, 0];
153 39
        $iSmallLen = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $iSmallLen is dead and can be removed.
Loading history...
154 39
        $iSBcnt = 0;
155 39
        $iCount = count($raList);
156 39
        for ($i = 0; $i < $iCount; ++$i) {
157 39
            if ($raList[$i]->Type == OLE::OLE_PPS_TYPE_FILE) {
158 39
                $raList[$i]->Size = $raList[$i]->getDataLen();
159 39
                if ($raList[$i]->Size < OLE::OLE_DATA_SIZE_SMALL) {
160 39
                    $iSBcnt += floor($raList[$i]->Size / $this->smallBlockSize)
161 39
                                  + (($raList[$i]->Size % $this->smallBlockSize) ? 1 : 0);
162
                } else {
163 21
                    $iBBcnt += (floor($raList[$i]->Size / $this->bigBlockSize) +
164 21
                        (($raList[$i]->Size % $this->bigBlockSize) ? 1 : 0));
165
                }
166
            }
167
        }
168 39
        $iSmallLen = $iSBcnt * $this->smallBlockSize;
169 39
        $iSlCnt = floor($this->bigBlockSize / OLE::OLE_LONG_INT_SIZE);
170 39
        $iSBDcnt = floor($iSBcnt / $iSlCnt) + (($iSBcnt % $iSlCnt) ? 1 : 0);
171 39
        $iBBcnt += (floor($iSmallLen / $this->bigBlockSize) +
172 39
                      (($iSmallLen % $this->bigBlockSize) ? 1 : 0));
173 39
        $iCnt = count($raList);
174 39
        $iBdCnt = $this->bigBlockSize / OLE::OLE_PPS_SIZE;
175 39
        $iPPScnt = (floor($iCnt / $iBdCnt) + (($iCnt % $iBdCnt) ? 1 : 0));
176
177 39
        return [$iSBDcnt, $iBBcnt, $iPPScnt];
178
    }
179
180
    /**
181
     * Helper function for caculating a magic value for block sizes.
182
     *
183
     * @param int $i2 The argument
184
     *
185
     * @see save()
186
     *
187
     * @return float
188
     */
189
    private static function adjust2($i2)
190
    {
191
        $iWk = log($i2) / log(2);
192
193
        return ($iWk > floor($iWk)) ? floor($iWk) + 1 : $iWk;
194
    }
195
196
    /**
197
     * Save OLE header.
198
     *
199
     * @param int $iSBDcnt
200
     * @param int $iBBcnt
201
     * @param int $iPPScnt
202
     */
203 39
    public function _saveHeader($iSBDcnt, $iBBcnt, $iPPScnt)
204
    {
205 39
        $FILE = $this->fileHandle;
206
207
        // Calculate Basic Setting
208 39
        $iBlCnt = $this->bigBlockSize / OLE::OLE_LONG_INT_SIZE;
209 39
        $i1stBdL = ($this->bigBlockSize - 0x4C) / OLE::OLE_LONG_INT_SIZE;
210
211 39
        $iBdExL = 0;
212 39
        $iAll = $iBBcnt + $iPPScnt + $iSBDcnt;
213 39
        $iAllW = $iAll;
214 39
        $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt) ? 1 : 0);
215 39
        $iBdCnt = floor(($iAll + $iBdCntW) / $iBlCnt) + ((($iAllW + $iBdCntW) % $iBlCnt) ? 1 : 0);
216
217
        // Calculate BD count
218 39 View Code Duplication
        if ($iBdCnt > $i1stBdL) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
219
            while (1) {
220
                ++$iBdExL;
221
                ++$iAllW;
222
                $iBdCntW = floor($iAllW / $iBlCnt) + (($iAllW % $iBlCnt) ? 1 : 0);
223
                $iBdCnt = floor(($iAllW + $iBdCntW) / $iBlCnt) + ((($iAllW + $iBdCntW) % $iBlCnt) ? 1 : 0);
224
                if ($iBdCnt <= ($iBdExL * $iBlCnt + $i1stBdL)) {
225
                    break;
226
                }
227
            }
228
        }
229
230
        // Save Header
231 39
        fwrite(
232 39
            $FILE,
233
            "\xD0\xCF\x11\xE0\xA1\xB1\x1A\xE1"
234
            . "\x00\x00\x00\x00"
235
            . "\x00\x00\x00\x00"
236
            . "\x00\x00\x00\x00"
237
            . "\x00\x00\x00\x00"
238 39
            . pack('v', 0x3b)
239 39
            . pack('v', 0x03)
240 39
            . pack('v', -2)
241 39
            . pack('v', 9)
242 39
            . pack('v', 6)
243 39
            . pack('v', 0)
244 39
            . "\x00\x00\x00\x00"
245 39
            . "\x00\x00\x00\x00"
246 39
            . pack('V', $iBdCnt)
247 39
            . pack('V', $iBBcnt + $iSBDcnt) //ROOT START
248 39
            . pack('V', 0)
249 39
            . pack('V', 0x1000)
250 39
            . pack('V', $iSBDcnt ? 0 : -2) //Small Block Depot
251 39
            . pack('V', $iSBDcnt)
252
        );
253
        // Extra BDList Start, Count
254 39
        if ($iBdCnt < $i1stBdL) {
255 39
            fwrite(
256 39
                $FILE,
257 39
                pack('V', -2) // Extra BDList Start
258 39
                . pack('V', 0)// Extra BDList Count
259
            );
260
        } else {
261
            fwrite($FILE, pack('V', $iAll + $iBdCnt) . pack('V', $iBdExL));
262
        }
263
264
        // BDList
265 39
        for ($i = 0; $i < $i1stBdL && $i < $iBdCnt; ++$i) {
266 39
            fwrite($FILE, pack('V', $iAll + $i));
267
        }
268 39
        if ($i < $i1stBdL) {
269 39
            $jB = $i1stBdL - $i;
270 39 View Code Duplication
            for ($j = 0; $j < $jB; ++$j) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
271 39
                fwrite($FILE, (pack('V', -1)));
272
            }
273
        }
274 39
    }
275
276
    /**
277
     * Saving big data (PPS's with data bigger than \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL).
278
     *
279
     * @param int $iStBlk
280
     * @param array &$raList Reference to array of PPS's
281
     */
282 39
    public function _saveBigData($iStBlk, &$raList)
283
    {
284 39
        $FILE = $this->fileHandle;
285
286
        // cycle through PPS's
287 39
        $iCount = count($raList);
288 39
        for ($i = 0; $i < $iCount; ++$i) {
289 39
            if ($raList[$i]->Type != OLE::OLE_PPS_TYPE_DIR) {
290 39
                $raList[$i]->Size = $raList[$i]->getDataLen();
291 39
                if (($raList[$i]->Size >= OLE::OLE_DATA_SIZE_SMALL) || (($raList[$i]->Type == OLE::OLE_PPS_TYPE_ROOT) && isset($raList[$i]->_data))) {
292 39
                    fwrite($FILE, $raList[$i]->_data);
293
294 39 View Code Duplication
                    if ($raList[$i]->Size % $this->bigBlockSize) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
295 36
                        fwrite($FILE, str_repeat("\x00", $this->bigBlockSize - ($raList[$i]->Size % $this->bigBlockSize)));
296
                    }
297
                    // Set For PPS
298 39
                    $raList[$i]->startBlock = $iStBlk;
299
                    $iStBlk +=
300 39
                            (floor($raList[$i]->Size / $this->bigBlockSize) +
301 39
                                (($raList[$i]->Size % $this->bigBlockSize) ? 1 : 0));
302
                }
303
            }
304
        }
305 39
    }
306
307
    /**
308
     * get small data (PPS's with data smaller than \PhpOffice\PhpSpreadsheet\Shared\OLE::OLE_DATA_SIZE_SMALL).
309
     *
310
     * @param array &$raList Reference to array of PPS's
311
     */
312 39
    public function _makeSmallData(&$raList)
313
    {
314 39
        $sRes = '';
315 39
        $FILE = $this->fileHandle;
316 39
        $iSmBlk = 0;
317
318 39
        $iCount = count($raList);
319 39
        for ($i = 0; $i < $iCount; ++$i) {
320
            // Make SBD, small data string
321 39
            if ($raList[$i]->Type == OLE::OLE_PPS_TYPE_FILE) {
322 39
                if ($raList[$i]->Size <= 0) {
323
                    continue;
324
                }
325 39
                if ($raList[$i]->Size < OLE::OLE_DATA_SIZE_SMALL) {
326 39
                    $iSmbCnt = floor($raList[$i]->Size / $this->smallBlockSize)
327 39
                                  + (($raList[$i]->Size % $this->smallBlockSize) ? 1 : 0);
328
                    // Add to SBD
329 39
                    $jB = $iSmbCnt - 1;
330 39 View Code Duplication
                    for ($j = 0; $j < $jB; ++$j) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
331 39
                        fwrite($FILE, pack('V', $j + $iSmBlk + 1));
332
                    }
333 39
                    fwrite($FILE, pack('V', -2));
334
335
                    // Add to Data String(this will be written for RootEntry)
336 39
                    $sRes .= $raList[$i]->_data;
337 39 View Code Duplication
                    if ($raList[$i]->Size % $this->smallBlockSize) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
338 39
                        $sRes .= str_repeat("\x00", $this->smallBlockSize - ($raList[$i]->Size % $this->smallBlockSize));
339
                    }
340
                    // Set for PPS
341 39
                    $raList[$i]->startBlock = $iSmBlk;
342 39
                    $iSmBlk += $iSmbCnt;
343
                }
344
            }
345
        }
346 39
        $iSbCnt = floor($this->bigBlockSize / OLE::OLE_LONG_INT_SIZE);
347 39
        if ($iSmBlk % $iSbCnt) {
348 39
            $iB = $iSbCnt - ($iSmBlk % $iSbCnt);
349 39 View Code Duplication
            for ($i = 0; $i < $iB; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
350 39
                fwrite($FILE, pack('V', -1));
351
            }
352
        }
353
354 39
        return $sRes;
355
    }
356
357
    /**
358
     * Saves all the PPS's WKs.
359
     *
360
     * @param array $raList Reference to an array with all PPS's
361
     */
362 39
    public function _savePps(&$raList)
363
    {
364
        // Save each PPS WK
365 39
        $iC = count($raList);
366 39
        for ($i = 0; $i < $iC; ++$i) {
367 39
            fwrite($this->fileHandle, $raList[$i]->_getPpsWk());
368
        }
369
        // Adjust for Block
370 39
        $iCnt = count($raList);
371 39
        $iBCnt = $this->bigBlockSize / OLE::OLE_PPS_SIZE;
372 39
        if ($iCnt % $iBCnt) {
373
            fwrite($this->fileHandle, str_repeat("\x00", ($iBCnt - ($iCnt % $iBCnt)) * OLE::OLE_PPS_SIZE));
374
        }
375 39
    }
376
377
    /**
378
     * Saving Big Block Depot.
379
     *
380
     * @param int $iSbdSize
381
     * @param int $iBsize
382
     * @param int $iPpsCnt
383
     */
384 39
    public function _saveBbd($iSbdSize, $iBsize, $iPpsCnt)
385
    {
386 39
        $FILE = $this->fileHandle;
387
        // Calculate Basic Setting
388 39
        $iBbCnt = $this->bigBlockSize / OLE::OLE_LONG_INT_SIZE;
389 39
        $i1stBdL = ($this->bigBlockSize - 0x4C) / OLE::OLE_LONG_INT_SIZE;
390
391 39
        $iBdExL = 0;
392 39
        $iAll = $iBsize + $iPpsCnt + $iSbdSize;
393 39
        $iAllW = $iAll;
394 39
        $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt) ? 1 : 0);
395 39
        $iBdCnt = floor(($iAll + $iBdCntW) / $iBbCnt) + ((($iAllW + $iBdCntW) % $iBbCnt) ? 1 : 0);
396
        // Calculate BD count
397 39 View Code Duplication
        if ($iBdCnt > $i1stBdL) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
398
            while (1) {
399
                ++$iBdExL;
400
                ++$iAllW;
401
                $iBdCntW = floor($iAllW / $iBbCnt) + (($iAllW % $iBbCnt) ? 1 : 0);
402
                $iBdCnt = floor(($iAllW + $iBdCntW) / $iBbCnt) + ((($iAllW + $iBdCntW) % $iBbCnt) ? 1 : 0);
403
                if ($iBdCnt <= ($iBdExL * $iBbCnt + $i1stBdL)) {
404
                    break;
405
                }
406
            }
407
        }
408
409
        // Making BD
410
        // Set for SBD
411 39
        if ($iSbdSize > 0) {
412 39 View Code Duplication
            for ($i = 0; $i < ($iSbdSize - 1); ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
413
                fwrite($FILE, pack('V', $i + 1));
414
            }
415 39
            fwrite($FILE, pack('V', -2));
416
        }
417
        // Set for B
418 39 View Code Duplication
        for ($i = 0; $i < ($iBsize - 1); ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
419 39
            fwrite($FILE, pack('V', $i + $iSbdSize + 1));
420
        }
421 39
        fwrite($FILE, pack('V', -2));
422
423
        // Set for PPS
424 39 View Code Duplication
        for ($i = 0; $i < ($iPpsCnt - 1); ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
425
            fwrite($FILE, pack('V', $i + $iSbdSize + $iBsize + 1));
426
        }
427 39
        fwrite($FILE, pack('V', -2));
428
        // Set for BBD itself ( 0xFFFFFFFD : BBD)
429 39
        for ($i = 0; $i < $iBdCnt; ++$i) {
430 39
            fwrite($FILE, pack('V', 0xFFFFFFFD));
431
        }
432
        // Set for ExtraBDList
433 39
        for ($i = 0; $i < $iBdExL; ++$i) {
434
            fwrite($FILE, pack('V', 0xFFFFFFFC));
435
        }
436
        // Adjust for Block
437 39
        if (($iAllW + $iBdCnt) % $iBbCnt) {
438 39
            $iBlock = ($iBbCnt - (($iAllW + $iBdCnt) % $iBbCnt));
439 39
            for ($i = 0; $i < $iBlock; ++$i) {
440 39
                fwrite($FILE, pack('V', -1));
441
            }
442
        }
443
        // Extra BDList
444 39
        if ($iBdCnt > $i1stBdL) {
445
            $iN = 0;
446
            $iNb = 0;
447
            for ($i = $i1stBdL; $i < $iBdCnt; $i++, ++$iN) {
448
                if ($iN >= ($iBbCnt - 1)) {
449
                    $iN = 0;
450
                    ++$iNb;
451
                    fwrite($FILE, pack('V', $iAll + $iBdCnt + $iNb));
452
                }
453
                fwrite($FILE, pack('V', $iBsize + $iSbdSize + $iPpsCnt + $i));
454
            }
455
            if (($iBdCnt - $i1stBdL) % ($iBbCnt - 1)) {
456
                $iB = ($iBbCnt - 1) - (($iBdCnt - $i1stBdL) % ($iBbCnt - 1));
457 View Code Duplication
                for ($i = 0; $i < $iB; ++$i) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
458
                    fwrite($FILE, pack('V', -1));
459
                }
460
            }
461
            fwrite($FILE, pack('V', -2));
462
        }
463 39
    }
464
}
465