File: UploadedFile.php Lines 29 to 48
29    private $stream;
30
31    /**
32     * @param string|resource|\Psr\Http\Message\StreamInterface $streamOrFile
33     * @param int $size UPLOAD_ERR_* constant
34     * @param int $errorCode
35     * @param string $clientFilename
36     * @param string $clientMediaType
37     */
Type Class Description
pmd CyclomaticComplexity The method __construct() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
pmd NPathComplexity The method __construct() has an NPath complexity of 360. The configured NPath complexity threshold is 200.
38
Type Class Description
pmd CyclomaticComplexity The method __construct() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10.
pmd NPathComplexity The method __construct() has an NPath complexity of 360. The configured NPath complexity threshold is 200.
    public function __construct($streamOrFile, $size, $errorCode, $clientFilename=null, $clientMediaType=null) {
39        if($errorCode === UPLOAD_ERR_OK) {
40            if(is_string($streamOrFile)) {
41                $this->file = $streamOrFile;
42            } else if(is_resource($streamOrFile)) {
43                $this->stream = new Stream($streamOrFile);
44            } else if($streamOrFile instanceof \Psr\Http\Message\StreamInterface) {
45                $this->stream = $streamOrFile;
46            } else {
47                throw new \InvalidArgumentException('Invalid stream or file provided for UploadedFile');
48            }
 
File: UploadedFile.php Lines 68 to 87
68        }
69        $this->clientMediaType = $clientMediaType;
70    }
71
72    /**
73     * $_FILES の1件分から作成する
74     * @param array $file
75     * @return \Puyo\Psr7\UploadedFile
76     */
Type Class Description
checkstyle NotCamelCaps Method name "UploadedFile::createBy_FILE" is not in camel caps format
77
Type Class Description
checkstyle NotCamelCaps Method name "UploadedFile::createBy_FILE" is not in camel caps format
    static public function createBy_FILE(array $file) {
78        return new UploadedFile($file['tmp_name'], $file['size'], $file['error'], $file['name'], $file['type']);
79    }
80
81    /**
82     * {@inheritdoc}
83     * @return \Psr\Http\Message\StreamInterface
84     * @throws \RuntimeException if the upload was not successful.
85     */
86    public function getStream() {
87        if(!$this->isUploadOk()) {
 
File: UploadedFile.php Lines 150 to 169
150    /**
151     * {@inheritdoc}
152     * @return string
153     */
154    public function getClientMediaType() {
155        return $this->clientMediaType;
156    }
157
158    private function writeFile($path) {
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
159
Type Class Description
pmd ShortVariable Avoid variables with short names like $fp. Configured minimum length is 3.
        $fp = fopen($path, 'wb+');
160        if(!is_resource($fp)) {
161            throw new \RuntimeException('Unable to write to designated path');
162        }
163
164        $stream = $this->getStream();
165        while(!$stream->eof()) {
166            fwrite($fp, $stream->read(4096));
167        }
168
169        fclose($fp);