Completed
Push — master ( 7113c4...8875d3 )
by Yassine
14s
created

TransferChunk::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 5
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Copyright 2017 Facebook, Inc.
4
 *
5
 * You are hereby granted a non-exclusive, worldwide, royalty-free license to
6
 * use, copy, modify, and distribute this software in source code or binary
7
 * form for use in connection with the web services and APIs provided by
8
 * Facebook.
9
 *
10
 * As with any software that integrates with the Facebook platform, your use
11
 * of this software is subject to the Facebook Developer Principles and
12
 * Policies [http://developers.facebook.com/policy/]. This copyright notice
13
 * shall be included in all copies or substantial portions of the software.
14
 *
15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21
 * DEALINGS IN THE SOFTWARE.
22
 */
23
namespace Facebook\FileUpload;
24
25
/**
26
 * @package Facebook
27
 */
28
class TransferChunk
29
{
30
    /**
31
     * @var File the file to chunk during upload
32
     */
33
    private $file;
34
35
    /**
36
     * @var int the ID of the upload session
37
     */
38
    private $uploadSessionId;
39
40
    /**
41
     * @var int start byte position of the next file chunk
42
     */
43
    private $startOffset;
44
45
    /**
46
     * @var int end byte position of the next file chunk
47
     */
48
    private $endOffset;
49
50
    /**
51
     * @var int the ID of the video
52
     */
53
    private $videoId;
54
55
    /**
56
     * @param File $file
57
     * @param int  $uploadSessionId
58
     * @param int  $videoId
59
     * @param int  $startOffset
60
     * @param int  $endOffset
61
     */
62 4
    public function __construct(File $file, $uploadSessionId, $videoId, $startOffset, $endOffset)
63
    {
64 4
        $this->file = $file;
65 4
        $this->uploadSessionId = $uploadSessionId;
66 4
        $this->videoId = $videoId;
67 4
        $this->startOffset = $startOffset;
68 4
        $this->endOffset = $endOffset;
69 4
    }
70
71
    /**
72
     * Return the file entity.
73
     *
74
     * @return File
75
     */
76 2
    public function getFile()
77
    {
78 2
        return $this->file;
79
    }
80
81
    /**
82
     * Return a File entity with partial content.
83
     *
84
     * @return File
85
     */
86 4
    public function getPartialFile()
87
    {
88 4
        $maxLength = $this->endOffset - $this->startOffset;
89
90 4
        return new File($this->file->getFilePath(), $maxLength, $this->startOffset);
91
    }
92
93
    /**
94
     * Return upload session Id.
95
     *
96
     * @return int
97
     */
98 4
    public function getUploadSessionId()
99
    {
100 4
        return $this->uploadSessionId;
101
    }
102
103
    /**
104
     * Check whether is the last chunk.
105
     *
106
     * @return bool
107
     */
108 1
    public function isLastChunk()
109
    {
110 1
        return $this->startOffset === $this->endOffset;
111
    }
112
113
    /**
114
     * @return int
115
     */
116 4
    public function getStartOffset()
117
    {
118 4
        return $this->startOffset;
119
    }
120
121
    /**
122
     * Get uploaded video Id.
123
     *
124
     * @return int
125
     */
126 2
    public function getVideoId()
127
    {
128 2
        return $this->videoId;
129
    }
130
}
131