Skip to content

Commit

Permalink
Merge pull request mautic#3954 from escopecz/phpcs-fixer-ci
Browse files Browse the repository at this point in the history
Add PHP CS check to CI
  • Loading branch information
virlatinus authored May 30, 2017
2 parents e30b62e + 8fe110f commit d5b008d
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 59 deletions.
9 changes: 9 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__.'/app/bundles')
->in(__DIR__.'/app/config')
->in(__DIR__.'/app/middlewares')
->in(__DIR__.'/app/migrations')
->in(__DIR__.'/plugins');

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->finder($finder)
->fixers([
'align_double_arrow',
'align_equals',
Expand Down
17 changes: 11 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
language: php

php:
# At the moment Composer can't resolve dependencies for these PHP versions.
#- 5.3
#- 5.4
#- 5.5
- 5.6
- 7.0
- 7.1

before_script:
before_install:

# turn off XDebug
- phpenv config-rm xdebug.ini || return

# install dependencies in parallel
- travis_retry composer global require hirak/prestissimo

install:
- composer install

script:
- composer run-script test
- composer test
- bin/php-cs-fixer fix -v --dry-run --diff
6 changes: 3 additions & 3 deletions app/bundles/CampaignBundle/Controller/CampaignController.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,10 +650,10 @@ protected function getViewArguments(array $args, $action)
];

foreach ($events as $event) {
$event['logCount'] =
$event['percent'] =
$event['logCount'] =
$event['percent'] =
$event['yesPercent'] =
$event['noPercent'] = 0;
$event['noPercent'] = 0;

if (isset($campaignLogCounts[$event['id']])) {
$event['logCount'] = array_sum($campaignLogCounts[$event['id']]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@
*/
class FailedLeadEventLogRepository extends CommonRepository
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public function getCampaignLogCounts($campaignId, $excludeScheduled = false, $ex
];
}

$key = (int) $l['non_action_path_taken'] ? 0 : 1;
$key = (int) $l['non_action_path_taken'] ? 0 : 1;
$return[$l['event_id']][$key] = (int) $l['lead_count'];
} else {
$return[$l['event_id']] = (int) $l['lead_count'];
Expand Down
6 changes: 3 additions & 3 deletions app/bundles/CampaignBundle/Model/CampaignModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1285,11 +1285,11 @@ public function getCampaignMetricsLineChartData($unit, \DateTime $dateFrom, \Dat
$failedSq->expr()->eq('fe.log_id', 't.id')
);
$filter['failed_events'] = [
'subquery' => sprintf('NOT EXISTS (%s)', $failedSq->getSQL())
'subquery' => sprintf('NOT EXISTS (%s)', $failedSq->getSQL()),
];

$q = $query->prepareTimeDataQuery('campaign_lead_event_log', 'date_triggered', $filter);
$rawData = $q->execute()->fetchAll();
$q = $query->prepareTimeDataQuery('campaign_lead_event_log', 'date_triggered', $filter);
$rawData = $q->execute()->fetchAll();

if (!empty($rawData)) {
$triggers = $query->completeTimeData($rawData);
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/ChannelBundle/Helper/ChannelListHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@ protected function setupChannels()
unset($event);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,45 @@

namespace Mautic\ConfigBundle\Tests\EventListener;

use Mautic\ConfigBundle\EventListener\ConfigSubscriber;
use Mautic\ConfigBundle\Event\ConfigEvent;
use Mautic\ConfigBundle\EventListener\ConfigSubscriber;

class ConfigSubscriberTest extends \PHPUnit_Framework_TestCase {

public function testEscapePercentCharacters() {
class ConfigSubscriberTest extends \PHPUnit_Framework_TestCase
{
public function testEscapePercentCharacters()
{
$config = [
'regularValue' => 'Nothing to do here',
'single percent' => 'Still nothing % to do here',
'simple escape' => 'This will be %escaped%',
'regularValue' => 'Nothing to do here',
'single percent' => 'Still nothing % to do here',
'simple escape' => 'This will be %escaped%',
'do not escape valid vars' => 'this is cool var %kernel.root_dir%',
'escape complex string' => "
'escape complex string' => "
trk_tit = trk_tit.replace(/\\%u00a0/g, '');
trk_tit = trk_tit.replace(/\\%u2122/g, '');
trk_tit = trk_tit.replace(/\\%u[0-9][0-9][0-9][0-9]/g, '');
"
",
];
$configEscaped = [
'regularValue' => 'Nothing to do here',
'single percent' => 'Still nothing % to do here',
'simple escape' => 'This will be %%escaped%%',
'regularValue' => 'Nothing to do here',
'single percent' => 'Still nothing % to do here',
'simple escape' => 'This will be %%escaped%%',
'do not escape valid vars' => 'this is cool var %kernel.root_dir%',
'escape complex string' => "
'escape complex string' => "
trk_tit = trk_tit.replace(/\\%%u00a0/g, '');
trk_tit = trk_tit.replace(/\\%%u2122/g, '');
trk_tit = trk_tit.replace(/\\%u[0-9][0-9][0-9][0-9]/g, '');
"
",
];

$event = new ConfigEvent($config, $this->getMockBuilder('\Symfony\Component\HttpFoundation\ParameterBag')->getMock());
$event = new ConfigEvent($config, $this->getMockBuilder('\Symfony\Component\HttpFoundation\ParameterBag')->getMock());
$paramHelper = $this->getMockBuilder('\Mautic\CoreBundle\Helper\CoreParametersHelper')
->disableOriginalConstructor()
->getMock();
$paramHelper->method('getParameter')->will($this->returnCallback(function ($param) {
if($param === 'kernel.root_dir') {
if ($param === 'kernel.root_dir') {
return '/some/path';
}

return null;
}));

Expand Down
2 changes: 1 addition & 1 deletion app/bundles/CoreBundle/Controller/ExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function showAction(Request $request, FlattenException $exception, DebugL
strpos($request->getUri(), '/api') !== false ||
(!defined('MAUTIC_AJAX_VIEW') && strpos($request->server->get('HTTP_ACCEPT', ''), 'application/json') !== false)
) {
$message = ('dev' === MAUTIC_ENV) ? $exception->getMessage() : $this->get('translator')->trans('mautic.core.error.generic', ['%code%' => $code]);
$message = ('dev' === MAUTIC_ENV) ? $exception->getMessage() : $this->get('translator')->trans('mautic.core.error.generic', ['%code%' => $code]);
$dataArray = [
'errors' => [
[
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/CoreBundle/EventListener/BuildJsSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function onBuildJs(BuildJsEvent $event)
--- fingerprint2.js.orig 2017-05-15 15:02:12.600335908 +0200
+++ fingerprint2.js 2017-05-15 15:02:30.592522246 +0200
@@ -18,10 +18,7 @@
(function (name, context, definition) {
"use strict";
- if (typeof define === "function" && define.amd) { define(definition); }
Expand Down
14 changes: 7 additions & 7 deletions app/bundles/EmailBundle/Helper/MailHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,12 +476,12 @@ public function send($dispatchSendEvent = false, $isQueueFlush = false, $useOwne
*
* @param bool $dispatchSendEvent
* @param string $returnMode What should happen post send/queue to $this->message after the email send is attempted.
* Options are:
* RESET_TO resets the to recipients and resets errors
* FULL_RESET creates a new MauticMessage instance and resets errors
* DO_NOTHING leaves the current errors array and MauticMessage instance intact
* NOTHING_IF_FAILED leaves the current errors array MauticMessage instance intact if it fails, otherwise reset_to
* RETURN_ERROR return an array of [success, $errors]; only one applicable if message is queued
* Options are:
* RESET_TO resets the to recipients and resets errors
* FULL_RESET creates a new MauticMessage instance and resets errors
* DO_NOTHING leaves the current errors array and MauticMessage instance intact
* NOTHING_IF_FAILED leaves the current errors array MauticMessage instance intact if it fails, otherwise reset_to
* RETURN_ERROR return an array of [success, $errors]; only one applicable if message is queued
*
* @return bool
*/
Expand Down Expand Up @@ -1614,7 +1614,7 @@ protected function logError($error, $context = null)
// Clean up the error message
$errorMessage = trim(preg_replace('/(.*?)Log data:(.*)$/is', '$1', $errorMessage));

$this->fatal = true;
$this->fatal = true;
} else {
$errorMessage = trim($error);
}
Expand Down
10 changes: 5 additions & 5 deletions app/bundles/EmailBundle/Model/EmailModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,8 @@ public function sendEmail($email, $leads, $options = [])
$statEntities = [];
$statBatchCount = 0;
$emailSentCounts = [];
$badEmails = [];
$errorMessages = [];
$badEmails = [];
$errorMessages = [];

// Setup the mailer
$mailer = $this->mailHelper->getMailer(!$sendBatchMail);
Expand All @@ -1232,14 +1232,14 @@ public function sendEmail($email, $leads, $options = [])
if (!empty($sendFailures['failures'])) {
$failures = $sendFailures;
unset($sendFailures['failures']);
$error = implode("; ", $sendFailures);
$error = implode('; ', $sendFailures);

// Prevent the stat from saving
foreach ($failures as $failedEmail) {
/** @var Stat $stat */
$stat = $statEntities[$failedEmail];
// Add lead ID to list of failures
$errors[$stat->getLead()->getId()] = $failedEmail;
$errors[$stat->getLead()->getId()] = $failedEmail;
$errorMessages[$stat->getLead()->getId()] = $error;
// Down sent counts
$emailId = $stat->getEmail()->getId();
Expand All @@ -1251,7 +1251,7 @@ public function sendEmail($email, $leads, $options = [])
unset($statEntities[$failedEmail], $saveEntities[$failedEmail]);
}
} elseif ($singleEmail) {
$error = implode("; ", $sendFailures);
$error = implode('; ', $sendFailures);
$errorMessages[$singleEmail] = $error;
}
}
Expand Down
3 changes: 0 additions & 3 deletions app/bundles/EmailBundle/Tests/Helper/MailHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ class MailHelperTest extends \PHPUnit_Framework_TestCase
],
];

/**
*
*/
public function setUp()
{
defined('MAUTIC_ENV') or define('MAUTIC_ENV', 'test');
Expand Down
2 changes: 1 addition & 1 deletion app/bundles/PluginBundle/Command/FetchLeadsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (3 === count($result)) {
list($updated, $created, $errored) = $result;
} else {
$errored = '?';
$errored = '?';
list($updated, $created) = $result;
}
$output->writeln(
Expand Down
6 changes: 3 additions & 3 deletions app/bundles/PluginBundle/EventListener/CampaignSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public function onCampaignTriggerAction(CampaignExecutionEvent $event)
$errors = [];

/**
* @var $name
* @var AbstractIntegration $s
* @var
* @var AbstractIntegration $s
*/
foreach ($services as $name => $s) {
$settings = $s->getIntegrationSettings();
Expand All @@ -109,7 +109,7 @@ public function onCampaignTriggerAction(CampaignExecutionEvent $event)
}

if (count($errors)) {
$event->setFailed(implode("<br />", $errors));
$event->setFailed(implode('<br />', $errors));
}

return $event->setResult($success);
Expand Down
6 changes: 2 additions & 4 deletions app/migrations/Version20170506144649.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace Mautic\Migrations;

use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Migrations\SkipMigrationException;
use Doctrine\DBAL\Schema\Schema;
use Mautic\CoreBundle\Doctrine\AbstractMauticMigration;

/**
* Auto-generated Migration: Please modify to your needs!
Expand All @@ -28,7 +28,6 @@ class Version20170506144649 extends AbstractMauticMigration
public function preUp(Schema $schema)
{
if ($schema->hasTable(MAUTIC_TABLE_PREFIX.'campaign_lead_event_failed_log')) {

throw new SkipMigrationException('Schema includes this migration');
}
}
Expand All @@ -51,6 +50,5 @@ public function up(Schema $schema)

$fk = $this->generatePropertyName('campaign_lead_event_failed_log', 'fk', ['log_id']);
$this->addSql("ALTER TABLE {$this->prefix}campaign_lead_event_failed_log ADD CONSTRAINT {$fk} FOREIGN KEY (log_id) REFERENCES {$this->prefix}campaign_lead_event_log (id) ON DELETE CASCADE;");

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ public function getFormNotes($section)
{
if ('custom' === $section) {
return [
'template' => 'MauticOutlookBundle:Integration:form.html.php',
'template' => 'MauticOutlookBundle:Integration:form.html.php',
'parameters' => [
'mauticUrl' => UrlHelper::rel2abs('/index.php')
]
'mauticUrl' => UrlHelper::rel2abs('/index.php'),
],
];
}

Expand Down

0 comments on commit d5b008d

Please sign in to comment.