Passed
Push — master ( c1490b...95dfbb )
by Anthony
02:45
created

PackagesDistController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 22
c 2
b 0
f 0
dl 0
loc 73
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendPackageInformations() 0 11 2
A sendToken() 0 4 1
A sendComposerJson() 0 9 2
A changePackageVersion() 0 15 1
1
<?php
2
3
namespace PiouPiou\RibsAdminBundle\Controller;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Exception;
7
use PiouPiou\RibsAdminBundle\Entity\Package;
8
use PiouPiou\RibsAdminBundle\Service\Version;
9
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
10
use Symfony\Component\Console\Application;
11
use Symfony\Component\Console\Output\BufferedOutput;
12
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
13
use Symfony\Component\HttpFoundation\JsonResponse;
14
use Symfony\Component\HttpKernel\KernelInterface;
15
use Symfony\Component\Routing\Annotation\Route;
16
17
class PackagesDistController extends AbstractController
18
{
19
    /**
20
     * @Route("/packages/dist/send-package/{package_name}", name="ribsadmin_packages_dist_send", requirements={"package_name"=".+"})
21
     * @param EntityManagerInterface $em
22
     * @param Version $version
23
     * @param string $package_name
24
     * @return mixed|null
25
     * @throws Exception
26
     */
27
    public function sendPackageInformations(EntityManagerInterface $em, Version $version, string $package_name): JsonResponse
28
    {
29
        $package = $em->getRepository(Package::class)->findOneBy(["package_name" => $package_name]);
30
31
        if ($package) {
32
            $version->setPackageEntity($package);
33
        }
34
35
        return new JsonResponse([
36
            "package" => $version->getPackage(),
37
            "package_date" => $version->getVersionDate()
38
        ]);
39
    }
40
41
    /**
42
     * @Route("/packages/dist/send-composer-lock/", name="ribsadmin_packages_dist_send_composer_lock")
43
     * @return JsonResponse
44
     */
45
    public function sendComposerJson(): JsonResponse
46
    {
47
        $composer_lock = file_get_contents('../composer.lock');
48
49
        if ($composer_lock) {
50
            $composer_lock = json_decode($composer_lock);
51
        }
52
53
        return new JsonResponse($composer_lock);
54
    }
55
56
    /**
57
     * @Route("/packages/dist/send-token/", name="ribsadmin_packages_dist_send_token")
58
     * @param ParameterBagInterface $parameter
59
     * @return JsonResponse
60
     */
61
    public function sendToken(ParameterBagInterface $parameter): JsonResponse
62
    {
63
        return new JsonResponse([
64
            "token" => $parameter->get("ribs_admin.packages_token")
65
        ]);
66
    }
67
68
    /**
69
     * @Route("/packages/dist/change-version/{package_name}", name="ribsadmin_packages_dist_change_version", requirements={"package_name"=".+"})
70
     * @param KernelInterface $kernel
71
     * @param string $package_name
72
     * @return JsonResponse
73
     * @throws Exception
74
     */
75
    public function changePackageVersion(KernelInterface $kernel, string $package_name): JsonResponse
76
    {
77
        $application = new Application($kernel);
0 ignored issues
show
Bug introduced by
$kernel of type Symfony\Component\HttpKernel\KernelInterface is incompatible with the type string expected by parameter $name of Symfony\Component\Consol...lication::__construct(). ( Ignorable by Annotation )

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

77
        $application = new Application(/** @scrutinizer ignore-type */ $kernel);
Loading history...
78
        $application->setAutoExit(false);
79
80
        $input = new ArrayInput([
0 ignored issues
show
Bug introduced by
The type PiouPiou\RibsAdminBundle\Controller\ArrayInput 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...
81
            'command' => 'ribsadmin:change-package-version',
82
            'package-name' => $package_name,
83
        ]);
84
85
        $output = new BufferedOutput();
86
        $application->run($input, $output);
87
        $content = $output->fetch();
88
89
        return new JsonResponse($content);
90
    }
91
}
92