Skip to content

Commit

Permalink
Merge pull request #82 from ValentineBoineau/migrations
Browse files Browse the repository at this point in the history
Migrations
  • Loading branch information
tgalopin committed Jul 9, 2019
2 parents cbb1e34 + 161bd0b commit 53f146b
Show file tree
Hide file tree
Showing 26 changed files with 216 additions and 213 deletions.
14 changes: 14 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

return PhpCsFixer\Config::create()
->setRules(array(
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
))
->setRiskyAllowed(true)
->setFinder(
PhpCsFixer\Finder::create()
->in([__DIR__.'/Cli', __DIR__.'/Sdk'])
)
;
9 changes: 1 addition & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,11 @@ script:

jobs:
include:
- stage: test
php: 5.3
dist: precise
- php: 5.4
- php: 5.5
- php: 5.6
- php: 7.0
- php: 7.1
- php: 7.2
- php: 7.3
- stage: release
php: 5.3
php: 7.1
dist: precise
install:
- composer install --no-dev -o
Expand Down
6 changes: 3 additions & 3 deletions Cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Application extends SymfonyApplication

public function __construct()
{
$this->apiConfig = array(
$this->apiConfig = [
'base_url' => Api::ENDPOINT,
);
];

parent::__construct(static::APPLICATION_NAME, static::APPLICATION_VERSION);
}
Expand All @@ -48,7 +48,7 @@ public function getApi()
}

$config = $this->apiConfig;
if (array_key_exists('api_endpoint', $config)) {
if (\array_key_exists('api_endpoint', $config)) {
$config['base_url'] = $config['api_endpoint'];
}
$this->api = new Api($config);
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$api = $this->getApplication()->getApi();
$analysis = $api->analyze($projectUuid, $input->getOption('reference'), $input->getOption('branch'));

$chars = array('-', '\\', '|', '/');
$chars = ['-', '\\', '|', '/'];
$noAnsiStatus = 'Analysis queued';
$output->getErrorOutput()->writeln($noAnsiStatus);

Expand Down
12 changes: 6 additions & 6 deletions Cli/Command/ProjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace SensioLabs\Insight\Cli\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

Expand Down Expand Up @@ -42,21 +43,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('There are no projects');
}

$rows = array();
$rows = [];
foreach ($projects as $project) {
if ($project->getLastAnalysis()) {
$grade = $project->getLastAnalysis()->getGrade();
} else {
$grade = 'This project has no analyses';
}
$rows[] = array($project->getName(), $project->getUuid(), $grade);
$rows[] = [$project->getName(), $project->getUuid(), $grade];
}

$this
->getHelperSet()->get('table')
->setHeaders(array('name', 'uuid', 'grade'))
$table = new Table($output);
$table->setHeaders(['name', 'uuid', 'grade'])
->setRows($rows)
->render($output)
->render()
;
}
}
14 changes: 7 additions & 7 deletions Cli/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ public function setApiEndpoint($apiEndpoint)

public function toArray()
{
return array(
return [
'user_uuid' => $this->userUuid,
'api_token' => $this->apiToken,
'api_endpoint' => $this->apiEndpoint,
);
];
}

public function save()
{
file_put_contents($this->storagePath, json_encode($this->toArray()));
}

public function equals(Configuration $configuration)
public function equals(self $configuration)
{
if ($this->userUuid !== $configuration->userUuid) {
return false;
Expand All @@ -82,13 +82,13 @@ private function load()

$data = json_decode(file_get_contents($this->storagePath), true);

if (array_key_exists('user_uuid', $data)) {
if (\array_key_exists('user_uuid', $data)) {
$this->userUuid = $data['user_uuid'];
}
if (array_key_exists('api_token', $data)) {
if (\array_key_exists('api_token', $data)) {
$this->apiToken = $data['api_token'];
}
if (array_key_exists('api_endpoint', $data)) {
if (\array_key_exists('api_endpoint', $data)) {
$this->apiEndpoint = $data['api_endpoint'];
}
}
Expand All @@ -98,7 +98,7 @@ private function getStoragePath()
$storagePath = getenv('INSIGHT_HOME');

if (!$storagePath) {
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
if (\defined('PHP_WINDOWS_VERSION_MAJOR')) {
if (!getenv('APPDATA')) {
throw new \RuntimeException('The APPDATA or INSIGHT_HOME environment variable must be set for insight to run correctly');
}
Expand Down
6 changes: 3 additions & 3 deletions Cli/Descriptor/AbstractDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

abstract class AbstractDescriptor
{
public function describe($object, array $options = array())
public function describe($object, array $options = [])
{
if ($object instanceof Analysis) {
if (!$options['show_ignored_violations'] && $object->getViolations()) {
Expand All @@ -28,8 +28,8 @@ public function describe($object, array $options = array())
return $this->describeAnalysis($object, $options);
}

throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
throw new \InvalidArgumentException(sprintf('Object of type "%s" is not describable.', \get_class($object)));
}

abstract protected function describeAnalysis(Analysis $argument, array $options = array());
abstract protected function describeAnalysis(Analysis $argument, array $options = []);
}
2 changes: 1 addition & 1 deletion Cli/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Serializer $serializer)
$this->serializer = $serializer;
}

protected function describeAnalysis(Analysis $analysis, array $options = array())
protected function describeAnalysis(Analysis $analysis, array $options = [])
{
$output = $options['output'];
$output->writeln($this->serializer->serialize($analysis, 'json'));
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/PmdDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class PmdDescriptor extends AbstractDescriptor
const PHPMD_PRIORITY_MEDIUM_LOW = 4;
const PHPMD_PRIORITY_LOW = 5;

protected function describeAnalysis(Analysis $analysis, array $options = array())
protected function describeAnalysis(Analysis $analysis, array $options = [])
{
$output = $options['output'];

Expand Down
6 changes: 3 additions & 3 deletions Cli/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

class TextDescriptor extends AbstractDescriptor
{
protected function describeAnalysis(Analysis $analysis, array $options = array())
protected function describeAnalysis(Analysis $analysis, array $options = [])
{
$output = $options['output'];
if (OutputInterface::VERBOSITY_VERY_VERBOSE <= $output->getVerbosity()) {
Expand Down Expand Up @@ -67,15 +67,15 @@ protected function describeAnalysis(Analysis $analysis, array $options = array()
EOL;
foreach ($analysis->getViolations() as $violation) {
$output->writeln(strtr($template, array(
$output->writeln(strtr($template, [
'{{ resource }}' => $violation->getResource(),
'{{ line }}' => $violation->getLine(),
'{{ category }}' => $violation->getCategory(),
'{{ severity }}' => $violation->getSeverity(),
'{{ title }}' => $violation->getTitle(),
'{{ message }}' => $violation->getMessage(),
'{{ ignored }}' => $violation->isIgnored() ? ' (ignored)' : null,
)));
]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(Serializer $serializer)
$this->serializer = $serializer;
}

protected function describeAnalysis(Analysis $analysis, array $options = array())
protected function describeAnalysis(Analysis $analysis, array $options = [])
{
$output = $options['output'];
$output->writeln($this->serializer->serialize($analysis, 'xml'));
Expand Down
22 changes: 11 additions & 11 deletions Cli/Helper/ConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Symfony\Component\Console\Helper\Helper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;

class ConfigurationHelper extends Helper
{
Expand Down Expand Up @@ -97,18 +99,18 @@ private function askValue(InputInterface $input, OutputInterface $output, $varna
};

if (!$input->isInteractive()) {
return call_user_func($validator, $default);
return \call_user_func($validator, $default);
}

if ($default) {
$question = sprintf('What is your %s? [%s] ', $varname, $default);
$question = new Question(sprintf('What is your %s? [%s] ', $varname, $default));
} else {
$question = sprintf('What is your %s? ', $varname);
$question = new Question(sprintf('What is your %s? ', $varname));
}

$dialog = $this->getHelperSet()->get('dialog');
$dialog = $this->getHelperSet()->get('question');

return $dialog->askAndValidate($output, $question, $validator, false, $default);
return $dialog->ask($input, $output, $question, $validator, false, $default);
}

private function saveConfiguration(InputInterface $input, OutputInterface $output, Configuration $configuration)
Expand All @@ -119,13 +121,11 @@ private function saveConfiguration(InputInterface $input, OutputInterface $outpu
return;
}

$question = 'Do you want to save this new configuration? [Y/n] ';
if (PHP_VERSION_ID > 50400) {
$question = json_encode($configuration->toArray(), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n\n".$question;
}
$dialog = $this->getHelperSet()->get('dialog');
$question = new ConfirmationQuestion('Do you want to save this new configuration? [Y/n] ');

$dialog = $this->getHelperSet()->get('question');

if ($dialog->askConfirmation($output, $question)) {
if ($dialog->ask($input, $output, $question)) {
$configuration->save();
}
}
Expand Down
6 changes: 3 additions & 3 deletions Cli/Helper/DescriptorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class DescriptorHelper extends Helper
{
private $descriptors = array();
private $descriptors = [];

public function __construct(Serializer $serializer)
{
Expand All @@ -36,12 +36,12 @@ public function __construct(Serializer $serializer)

public function describe(OutputInterface $output, $object, $format = null, $showIgnoredViolation = false)
{
$options = array(
$options = [
'raw_text' => false,
'format' => $format ?: 'txt',
'output' => $output,
'show_ignored_violations' => $showIgnoredViolation,
);
];
$options['type'] = 'txt' === $options['format'] ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW;

if (!isset($this->descriptors[$options['format']])) {
Expand Down
14 changes: 7 additions & 7 deletions Cli/Helper/FailConditionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function __construct()

public function evaluate(Analysis $analysis, $expr)
{
$analysisData = array(
$analysisData = [
'grade' => $analysis->getGrade(),
'nbViolations' => 0,
'remediationCost' => $analysis->getRemediationCost(),
);
];

$counts = array(
$counts = [
// Category
'architecture' => 0,
'bugrisk' => 0,
Expand All @@ -47,20 +47,20 @@ public function evaluate(Analysis $analysis, $expr)
'major' => 0,
'minor' => 0,
'info' => 0,
);
];

$violations = $analysis->getViolations() ?: array();
$violations = $analysis->getViolations() ?: [];

foreach ($violations as $violation) {
++$counts[$violation->getCategory()];
++$counts[$violation->getSeverity()];
++$analysisData['nbViolations'];
}

$vars = array(
$vars = [
'analysis' => (object) $analysisData,
'counts' => (object) $counts,
);
];

if ($this->el->evaluate($expr, $vars)) {
return 70;
Expand Down
Loading

0 comments on commit 53f146b

Please sign in to comment.