CraftCamp /
official-website
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Model; |
||
| 4 | |||
| 5 | use Symfony\Component\HttpFoundation\File\UploadedFile; |
||
| 6 | |||
| 7 | abstract class Picture implements \JsonSerializable |
||
| 8 | { |
||
| 9 | const UPLOAD_DIR = 'images/uploads'; |
||
| 10 | |||
| 11 | /** @var string **/ |
||
| 12 | protected $name; |
||
| 13 | /** @var string **/ |
||
| 14 | protected $path; |
||
| 15 | /** @var File */ |
||
|
0 ignored issues
–
show
|
|||
| 16 | protected $file; |
||
| 17 | /** @var resource **/ |
||
| 18 | protected $temp; |
||
| 19 | |||
| 20 | 1 | public function setName(string $name): Picture |
|
| 21 | { |
||
| 22 | 1 | $this->name = $name; |
|
| 23 | |||
| 24 | 1 | return $this; |
|
| 25 | } |
||
| 26 | |||
| 27 | public function getName(): string |
||
| 28 | { |
||
| 29 | return $this->name; |
||
| 30 | } |
||
| 31 | |||
| 32 | public function setPath(string $path): Picture |
||
| 33 | { |
||
| 34 | $this->path = $path; |
||
| 35 | |||
| 36 | return $this; |
||
| 37 | } |
||
| 38 | |||
| 39 | public function getPath(): string |
||
| 40 | { |
||
| 41 | return $this->path; |
||
| 42 | } |
||
| 43 | |||
| 44 | 1 | public function setFile(UploadedFile $file = null): Picture |
|
| 45 | { |
||
| 46 | 1 | $this->file = $file; |
|
|
0 ignored issues
–
show
It seems like
$file can also be of type Symfony\Component\HttpFoundation\File\UploadedFile. However, the property $file is declared as type App\Model\File. 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 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...
|
|||
| 47 | // check if we have an old image path |
||
| 48 | 1 | if ($this->file !== null && is_file($this->getAbsolutePath())) { |
|
| 49 | // store the old name to delete after the update |
||
| 50 | $this->temp = $this->getAbsolutePath(); |
||
|
0 ignored issues
–
show
It seems like
$this->getAbsolutePath() of type string is incompatible with the declared type resource of property $temp.
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. Loading history...
|
|||
| 51 | $this->path = null; |
||
| 52 | } |
||
| 53 | 1 | return $this; |
|
| 54 | } |
||
| 55 | |||
| 56 | public function getFile(): UploadedFile |
||
| 57 | { |
||
| 58 | return $this->file; |
||
| 59 | } |
||
| 60 | |||
| 61 | 1 | public function getAbsolutePath(): string |
|
| 62 | { |
||
| 63 | 1 | return $this->getUploadRootDir() . '/' . $this->path; |
|
| 64 | } |
||
| 65 | |||
| 66 | 1 | public function getWebPath(): string |
|
| 67 | { |
||
| 68 | 1 | return $this->getUploadDir() . '/' . $this->path; |
|
| 69 | } |
||
| 70 | |||
| 71 | 1 | public function getUploadDir(): string |
|
| 72 | { |
||
| 73 | // the absolute directory path where uploaded |
||
| 74 | // documents should be saved |
||
| 75 | 1 | return '/' . self::UPLOAD_DIR; |
|
| 76 | } |
||
| 77 | |||
| 78 | 1 | public function getUploadRootDir(): string |
|
| 79 | { |
||
| 80 | 1 | return __DIR__ . '/../../public/' . self::UPLOAD_DIR; |
|
| 81 | } |
||
| 82 | |||
| 83 | 1 | public function jsonSerialize(): array |
|
| 84 | { |
||
| 85 | return [ |
||
| 86 | 1 | 'path' => $this->getWebPath() |
|
| 87 | ]; |
||
| 88 | } |
||
| 89 | |||
| 90 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths