Passed
Push — master ( 221f91...597eeb )
by Luiz Kim
02:20
created

FileUploadController::upload()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 21
rs 9.8666
cc 2
nc 2
nop 1
1
<?php
2
namespace ControleOnline\Controller;
3
4
use Symfony\Component\HttpFoundation\Request;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Request was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
5
use Symfony\Component\HttpFoundation\Response;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\Response was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpKe...BadRequestHttpException was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use ControleOnline\Entity\File;
8
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\Routing\Annotation\Route;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Routing\Annotation\Route was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
11
class FileUploadController
12
{
13
14
    public function __construct(private EntityManagerInterface $em)
15
    {
16
    }
17
18
    public function upload(Request $request): Response
19
    {
20
        /** @var UploadedFile $file */
21
        $file = $request->files->get('file');
22
23
        if (!$file) {
0 ignored issues
show
introduced by
$file is of type ControleOnline\Controller\UploadedFile, thus it always evaluated to true.
Loading history...
24
            throw new BadRequestHttpException('No file provided');
25
        }
26
27
        $content = file_get_contents($file->getPathname()); 
28
        $fileType = $file->getClientMimeType();
29
        $originalFilename = $file->getClientOriginalName();
0 ignored issues
show
Unused Code introduced by
The assignment to $originalFilename is dead and can be removed.
Loading history...
30
31
        $fileEntity = new File();
32
        $fileEntity->setContent($content);
33
        $fileEntity->setFileType($fileType);
34
35
        $this->em->persist($fileEntity);
36
        $this->em->flush();
37
38
        return new Response('File uploaded successfully', Response::HTTP_CREATED);
39
    }
40
}
41