<commit_before><?php

/**
 * This file is part of tenside/core.
 *
 * (c) <NAME> <https://github.com/discordier>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * This project is provided in good faith and hope to be usable by anyone.
 *
 * @package    tenside/core
 * @author     <NAME> <https://github.com/discordier>
 * @copyright  <NAME> <https://github.com/discordier>
 * @link       https://github.com/tenside/core
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
 * @filesource
 */

namespace Tenside\Web\Controller;

use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\Package\PackageInterface;
use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouteCollection;
use Tenside\Composer\PackageConverter;
use Tenside\Composer\SolverRunner;
use Tenside\Util\JsonArray;
use Tenside\Web\Auth\UserInformationInterface;

/**
 * List and manipulate the installed packages.
 */
class PackageController extends AbstractRestrictedController
{
    /**
     * {@inheritdoc}
     */
    public static function createRoutes(RouteCollection $routes)
    {
        $endpoint = '/api/v1/packages';
        static::createRoute($routes, 'packageList', $endpoint, ['GET']);
        static::createRoute(
            $routes,
            'getPackage',
            $endpoint . '/{vendor}/{package}',
            ['GET'],
            ['vendor' => '[\-\_a-zA-Z]*', 'package' => '[\-\_a-zA-Z]*']
        );
        static::createRoute(
            $routes,
            'putPackage',
            $endpoint . '/{vendor}/{package}',
            ['PUT'],
            ['vendor' => '[\-\_a-zA-Z]*', 'package' => '[\-\_a-zA-Z]*']
        );
        static::createRoute(
            $routes,
            'deletePackage',
            $endpoint . '/{vendor}/{package}',
            ['DELETE'],
            ['vendor' => '[\-\_a-zA-Z]*', 'package' => '[\-\_a-zA-Z]*']
        );
    }

    /**
     * Retrieve the package list.
     *
     * @param Request $request The request to process.
     *
     * @return JsonResponse
     *
     * @api
     */
    public function packageListAction(Request $request)
    {
        $this->needAccessLevel(UserInformationInterface::ACL_MANIPULATE_REQUIREMENTS);

        $composer  = $this->getTenside()->getComposer();
        $converter = new PackageConverter($composer->getPackage());
        if ($request->query->has('solve')) {
            $upgrades = $this->fullSolvePass();
        } else {
            $upgrades = $this->quickSolvePass();
        }

        $packages = $converter->convertRepositoryToArray(
            $composer->getRepositoryManager()->getLocalRepository(),
            !$request->query->has('all'),
            $upgrades
        );

        return new JsonResponse($packages->getData(), 200);
    }

    /**
     * Retrieve a package.
     *
     * @param string $vendor  The name of the vendor.
     *
     * @param string $package The name of the package.
     *
     * @return JsonResponse
     *
     * @api
     */
    public function getPackageAction($vendor, $package)
    {
        $this->needAccessLevel(UserInformationInterface::ACL_MANIPULATE_REQUIREMENTS);

        $packageName = $vendor . '/' . $package;

        $composer  = $this->getTenside()->getComposer();
        $converter = new PackageConverter($composer->getPackage());

        foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
            /** @var PackageInterface $package */
            if ($package->getPrettyName() === $packageName) {
                return new JsonResponse($converter->convertPackageToArray($package), 200);
            }
        }

        return new Response('Not found', 404);
    }

    /**
     * Retrieve a package.
     *
     * @param string  $vendor  The name of the vendor.
     *
     * @param string  $package The name of the package.
     *
     * @param Request $request The request to process.
     *
     * @return JsonResponse
     *
     * @api
     */
    public function putPackageAction($vendor, $package, Request $request)
    {
        $this->needAccessLevel(UserInformationInterface::ACL_MANIPULATE_REQUIREMENTS);

        $packageName = $vendor . '/' . $package;
        $info        = new JsonArray($request->getContent());

        if ($info->get('name') !== $packageName) {
            return new Response('Invalid payload', Response::HTTP_BAD_REQUEST);
        }

        $composer  = $this->getTenside()->getComposer();
        $converter = new PackageConverter($composer->getPackage());

        try {<commit_msg>phpDoc.<commit_after><?php

/**
 * This file is part of tenside/core.
 *
 * (c) <NAME> <https://github.com/discordier>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * This project is provided in good faith and hope to be usable by anyone.
 *
 * @package    tenside/core
 * @author     <NAME> <https://github.com/discordier>
 * @copyright  <NAME> <https://github.com/discordier>
 * @link       https://github.com/tenside/core
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
 * @filesource
 */

namespace Tenside\Web\Controller;

use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\Package\PackageInterface;
use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouteCollection;
use Tenside\Composer\PackageConverter;
use Tenside\Composer\SolverRunner;
use Tenside\Util\JsonArray;
use Tenside\Web\Auth\UserInformationInterface;

/**
 * List and manipulate the installed packages.
 */
class PackageController extends AbstractRestrictedController
{
    /**
     * {@inheritdoc}
     */
    public static function createRoutes(RouteCollection $routes)
    {
        $endpoint = '/api/v1/packages';
        static::createRoute($routes, 'packageList', $endpoint, ['GET']);
        static::createRoute(
            $routes,
            'getPackage',
            $endpoint . '/{vendor}/{package}',
            ['GET'],
            ['vendor' => '[\-\_a-zA-Z]*', 'package' => '[\-\_a-zA-Z]*']
        );
        static::createRoute(
            $routes,
            'putPackage',
            $endpoint . '/{vendor}/{package}',
            ['PUT'],
            ['vendor' => '[\-\_a-zA-Z]*', 'package' => '[\-\_a-zA-Z]*']
        );
        static::createRoute(
            $routes,
            'deletePackage',
            $endpoint . '/{vendor}/{package}',
            ['DELETE'],
            ['vendor' => '[\-\_a-zA-Z]*', 'package' => '[\-\_a-zA-Z]*']
        );
    }

    /**
     * Retrieve the package list.
     *
     * @param Request $request The request to process.
     *
     * @return JsonResponse
     *
     * @api
     */
    public function packageListAction(Request $request)
    {
        $this->needAccessLevel(UserInformationInterface::ACL_MANIPULATE_REQUIREMENTS);

        $composer  = $this->getTenside()->getComposer();
        $converter = new PackageConverter($composer->getPackage());
        if ($request->query->has('solve')) {
            $upgrades = $this->fullSolvePass();
        } else {
            $upgrades = $this->quickSolvePass();
        }

        $packages = $converter->convertRepositoryToArray(
            $composer->getRepositoryManager()->getLocalRepository(),
            !$request->query->has('all'),
            $upgrades
        );

        return new JsonResponse($packages->getData(), 200);
    }

    /**
     * Retrieve a package.
     *
     * @param string $vendor  The name of the vendor.
     *
     * @param string $package The name of the package.
     *
     * @return JsonResponse
     *
     * @api
     */
    public function getPackageAction($vendor, $package)
    {
        $this->needAccessLevel(UserInformationInterface::ACL_MANIPULATE_REQUIREMENTS);

        $packageName = $vendor . '/' . $package;

        $composer  = $this->getTenside()->getComposer();
        $converter = new PackageConverter($composer->getPackage());

        foreach ($composer->getRepositoryManager()->getLocalRepository()->getPackages() as $package) {
            /** @var PackageInterface $package */
            if ($package->getPrettyName() === $packageName) {
                return new JsonResponse($converter->convertPackageToArray($package), 200);
            }
        }

        return new Response('Not found', 404);
    }

    /**
     * Update the information of a package in the composer.json.
     *
     * @param string  $vendor  The name of the vendor.
     *
     * @param string  $package The name of the package.
     *
     * @param Request $request The request to process.
     *
     * @return JsonResponse
     *
     * @api
     */
    public function putPackageAction($vendor, $package, Request $request)
    {
        $this->needAccessLevel(UserInformationInterface::ACL_MANIPULATE_REQUIREMENTS);

        $packageName = $vendor . '/' . $package;
        $info        = new JsonArray($request->getContent());

        if ($info->get('name') !== $packageName) {
            return new Response('Invalid payload', Response::HTTP_BAD_REQUEST);
        }

        $composer  = $this->getTenside()->getComposer();
        $converter = new PackageConverter($composer->getPackage());

        try {
{'fraction_non_alphanumeric': 0.14367698298831727, 'fraction_numerical': 0.0020496003279360524, 'mean_word_length': 2.4618659098971265, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 85, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221269', 'n_tokens_mistral': 2805, 'n_tokens_neox': 2758, 'n_words': 576}