<commit_before><?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Service\ApiClient;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route("/health-check")
 */
class HealthCheckController extends Controller
{
    /**
     * @Route("/")
     * @Method({"GET"})
     * @Template
     */
    public function indexAction()
    {
        $data = [
            'api' => $this->getApiHealthData(),
            'client' => $this->getHealthData(),
        ];
        
        $response = $this->render('AppBundle:HealthCheck:index.html.twig', [
            'data' => $data
        ]);
        
        if (!$data['api']['healthy'] || !$data['client']['healthy']) {
            $response->setStatusCode('500');
        }
        
        return $response;
    }
    
    private function getHealthData()
    {
        $data = [
            'php_version' => version_compare(PHP_VERSION, "5.4") >= 0
        ];
        
        $data['healthy'] = count(array_filter($data)) === count($data);
        
        return $data;
    }
    
    
    private function getApiHealthData()
    {
        $content = $this->get('apiclient')->get('health-check')->getBody();
        $contentArray = json_decode($content, 1);
        if (json_last_error() !== JSON_ERROR_NONE || empty($contentArray['data'])) {
            throw new \RuntimeException("Cannot decode API response. " . json_last_error_msg());
        }
        return $contentArray['data'];
    }
}<commit_msg>add permission check client side<commit_after><?php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Service\ApiClient;
use Symfony\Component\HttpFoundation\Response;

/**
 * @Route("/health-check")
 */
class HealthCheckController extends Controller
{
    /**
     * @Route("/")
     * @Method({"GET"})
     * @Template
     */
    public function indexAction()
    {
        $data = [
            'api' => $this->getApiHealthData(),
            'client' => $this->getHealthData(),
        ];
        
        $response = $this->render('AppBundle:HealthCheck:index.html.twig', [
            'data' => $data
        ]);
        
        if (!$data['api']['healthy'] || !$data['client']['healthy']) {
            $response->setStatusCode('500');
        }
        
        return $response;
    }
    
    private function getHealthData()
    {
        $data = [
            'php_version' => version_compare(PHP_VERSION, "5.4") >= 0,
            'permissions_app/log' => $this->areLogPermissionCorrect(),
            'permissions_app/cache' => $this->areCachePermissionCorrect(),
        ];
        
        $data['healthy'] = count(array_filter($data)) === count($data);
        
        return $data;
    }
    
    
    private function getApiHealthData()
    {
        $content = $this->get('apiclient')->get('health-check')->getBody();
        $contentArray = json_decode($content, 1);
        if (json_last_error() !== JSON_ERROR_NONE || empty($contentArray['data'])) {
            throw new \RuntimeException("Cannot decode API response. " . json_last_error_msg());
        }
        return $contentArray['data'];
    }
    
    private function areLogPermissionCorrect()
    {
        return is_writable($this->get('kernel')->getRootDir() . '/logs/');
    }
    
    private function areCachePermissionCorrect()
    {
        return is_writable($this->get('kernel')->getRootDir() . '/cache/');
    }
}
{'fraction_non_alphanumeric': 0.15570574473615806, 'fraction_numerical': 0.00363919937613725, 'mean_word_length': 2.5465437788018432, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, 'https://': 0, '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': '1080109', 'n_tokens_mistral': 1098, 'n_tokens_neox': 1084, 'n_words': 170}