Commit 3157d6a5 authored by Thomas Citharel's avatar Thomas Citharel
Browse files

Run php-cs-fixer with a custom config. This may break a lot of things


Signed-off-by: default avatarThomas Citharel <tcit@tcit.fr>
parent 9827070b
......@@ -9,6 +9,7 @@ app/inc/config.php
vendor
cache/
tpl_c/
.php_cs.cache
# Temp files
*~
......
<?php
return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'array_syntax' => [
'syntax' => 'short'
],
'combine_consecutive_unsets' => true,
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => [
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block'
],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_strict' => true,
'phpdoc_order' => true,
// 'psr4' => true,
'strict_comparison' => true,
'strict_param' => true,
'concat_space' => [
'spacing' => 'one'
],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude([
'vendor',
'var',
'web'
])
->in(__DIR__)
)
;
......@@ -16,13 +16,13 @@
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Services\LogService;
use Framadate\Services\PollService;
use Framadate\Message;
use Framadate\Services\InputService;
use Framadate\Services\LogService;
use Framadate\Services\MailService;
use Framadate\Services\NotificationService;
use Framadate\Services\PollService;
use Framadate\Services\SecurityService;
use Framadate\Message;
include_once __DIR__ . '/../app/inc/init.php';
......@@ -33,7 +33,7 @@ $poll_id = null;
$poll = null;
$message = null;
$result = false;
$comments = array();
$comments = [];
$is_admin = false;
/* Services */
......@@ -57,7 +57,7 @@ if (!empty($_POST['poll'])) {
if (!empty($_POST['poll_admin'])) {
$admin_poll_id = filter_input(INPUT_POST, 'poll_admin', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
if (strlen($admin_poll_id) === 24) {
$is_admin = ($pollService->findByAdminId($admin_poll_id) != null);
$is_admin = ($pollService->findByAdminId($admin_poll_id) !== null);
}
}
......@@ -69,11 +69,11 @@ if (!$poll) {
$name = $inputService->filterName($_POST['name']);
$comment = $inputService->filterComment($_POST['comment']);
if ($name == null) {
if ($name === null) {
$message = new Message('danger', __('Error', 'The name is invalid.'));
}
if ($message == null) {
if ($message === null) {
// Add comment
$result = $pollService->addComment($poll_id, $name, $comment);
if ($result) {
......@@ -90,6 +90,6 @@ $smarty->error_reporting = E_ALL & ~E_NOTICE;
$smarty->assign('comments', $comments);
$comments_html = $smarty->fetch('part/comments_list.tpl');
$response = array('result' => $result, 'message' => $message, 'comments' => $comments_html);
$response = ['result' => $result, 'message' => $message, 'comments' => $comments_html];
echo json_encode($response);
......@@ -17,11 +17,11 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Services\SessionService;
use Framadate\Services\PollService;
use Framadate\Services\MailService;
use Framadate\Services\LogService;
use Framadate\Message;
use Framadate\Services\LogService;
use Framadate\Services\MailService;
use Framadate\Services\PollService;
use Framadate\Services\SessionService;
use Framadate\Utils;
include_once __DIR__ . '/../app/inc/init.php';
......@@ -45,7 +45,7 @@ if (!empty($_POST['poll'])) {
$token = $sessionService->get("Common", SESSION_EDIT_LINK_TOKEN);
$token_form_value = empty($_POST['token']) ? null : $_POST['token'];
$editedVoteUniqueId = filter_input(INPUT_POST, 'editedVoteUniqueId', FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => POLL_REGEX]]);
if (is_null($poll) || $config['use_smtp'] == false || is_null($token) || is_null($token_form_value)
if (is_null($poll) || $config['use_smtp'] === false || is_null($token) || is_null($token_form_value)
|| !$token->check($token_form_value) || is_null($editedVoteUniqueId)) {
$message = new Message('error', __('Error', 'Something is going wrong...'));
}
......@@ -69,7 +69,6 @@ if (is_null($message)) {
}
}
if (is_null($message)) {
$url = Utils::getUrlSondage($poll_id, false, $editedVoteUniqueId);
......@@ -78,7 +77,7 @@ if (is_null($message)) {
$smarty->assign('editedVoteUniqueId', $editedVoteUniqueId);
$body = $smarty->fetch('mail/remember_edit_link.tpl');
$subject = '[' . NOMAPPLICATION . ']['.__('EditLink', 'REMINDER').'] '.__f('EditLink', 'Edit link for poll "%s"', $poll->title);
$subject = '[' . NOMAPPLICATION . '][' . __('EditLink', 'REMINDER') . '] ' . __f('EditLink', 'Edit link for poll "%s"', $poll->title);
//$mailService->send($email, $subject, $body);
$sessionService->remove("Common", SESSION_EDIT_LINK_TOKEN);
......@@ -90,7 +89,6 @@ if (is_null($message)) {
$smarty->error_reporting = E_ALL & ~E_NOTICE;
$response = array('result' => $result, 'message' => $message);
$response = ['result' => $result, 'message' => $message];
echo json_encode($response);
\ No newline at end of file
......@@ -35,7 +35,7 @@ if (!file_exists(ROOT_DIR . 'vendor/autoload.php') || !file_exists(ROOT_DIR . 'v
require_once ROOT_DIR . 'vendor/autoload.php';
require_once ROOT_DIR . 'vendor/o80/i18n/src/shortcuts.php';
require_once ROOT_DIR . 'app/inc/constants.php';
if (session_id() == '') {
if (session_id() === '') {
session_start();
}
$ALLOWED_LANGUAGES = [
......@@ -59,27 +59,26 @@ require_once ROOT_DIR . 'app/inc/i18n.php';
*/
function compareCheckMessage(Message $a, Message $b)
{
$values = array(
$values = [
'danger' => 0,
'warning' => 1,
'info' => 2,
'success' => 3
);
];
$vA = $values[$a->type];
$vB = $values[$b->type];
if ($vA == $vB) {
if ($vA === $vB) {
return 0;
}
return ($vA < $vB) ? -1 : 1;
}
/**
* Vars
*/
$messages = array();
$inc_directory = ROOT_DIR. 'app/inc/';
$messages = [];
$inc_directory = ROOT_DIR . 'app/inc/';
$conf_filename = $inc_directory . 'config.php';
/**
......@@ -133,14 +132,13 @@ if (!empty($timezone)) {
$messages[] = new Message('warning', __('Check','Consider setting the date.timezone in php.ini.'));
}
// The percentage of steps needed to be ready to launch the application
$errors = 0;
$warnings = 0;
foreach ($messages as $message) {
if ($message->type == 'danger') {
if ($message->type === 'danger') {
$errors++;
} else if ($message->type == 'warning') {
} else if ($message->type === 'warning') {
$warnings++;
}
}
......@@ -175,7 +173,7 @@ usort($messages, 'compareCheckMessage');
<div class="input-group input-group-sm pull-right col-xs-12 col-sm-2">
<select name="lang" class="form-control" title="<?=__('Language selector', 'Select the language')?>" >
<?php foreach ($ALLOWED_LANGUAGES as $lang_key => $language) { ?>
<option lang="fr" <?php if (substr($lang_key, 0, 2)==$locale) { echo 'selected';} ?> value="<?=substr($lang_key, 0, 2)?>"><?=$language?></option>
<option lang="fr" <?php if (substr($lang_key, 0, 2)===$locale) { echo 'selected';} ?> value="<?=substr($lang_key, 0, 2)?>"><?=$language?></option>
<?php } ?>
</select>
<span class="input-group-btn">
......@@ -197,9 +195,9 @@ usort($messages, 'compareCheckMessage');
<div>
<?php
foreach ($messages as $message) {
echo '<div class="alert alert-'. $message->type .'" role="alert">';
echo '<div class="alert alert-' . $message->type . '" role="alert">';
echo Utils::htmlEscape($message->message);
echo '<span class="sr-only">'. $message->type .'</span>';
echo '<span class="sr-only">' . $message->type . '</span>';
echo '</div>';
}
?>
......@@ -209,7 +207,7 @@ usort($messages, 'compareCheckMessage');
<a class="btn btn-info" role="button" href=""><span class="glyphicon glyphicon-refresh" aria-hidden="true"></span> <?= __('Check', 'Check again') ?></a>
<?php
if (!is_file($conf_filename)) {
if ($errors == 0) {
if ($errors === 0) {
?>
<a class="btn btn-primary" role="button" href="<?= Utils::get_server_name() . 'admin/install.php' ?>"><span class=" glyphicon glyphicon-arrow-right" aria-hidden="true"></span> <?= __('Check', 'Continue the installation') ?></a>
<?php
......
......@@ -37,9 +37,8 @@ if (!empty($_POST)) {
if ($result['status'] === 'OK') {
header(('Location: ' . Utils::get_server_name() . 'admin/migration.php'));
exit;
} else {
}
$error = __('Error', $result['code']);
}
}
$smarty->assign('error', $error);
......
......@@ -17,15 +17,15 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
use Framadate\Migration\From_0_0_to_0_8_Migration;
use Framadate\Migration\From_0_8_to_0_9_Migration;
use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9;
use Framadate\Migration\AddColumn_receiveNewComments_For_0_9;
use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9;
use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9;
use Framadate\Migration\Alter_Comment_table_for_name_length;
use Framadate\Migration\AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9;
use Framadate\Migration\Alter_Comment_table_adding_date;
use Framadate\Migration\Alter_Comment_table_for_name_length;
use Framadate\Migration\From_0_0_to_0_8_Migration;
use Framadate\Migration\From_0_8_to_0_9_Migration;
use Framadate\Migration\Generate_uniqId_for_old_votes;
use Framadate\Migration\AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9;
use Framadate\Migration\Increase_pollId_size;
use Framadate\Migration\Migration;
use Framadate\Migration\RPadVotes_from_0_8;
......@@ -56,7 +56,7 @@ $tables = $connect->allTables();
$pdo = $connect->getPDO();
$prefixedMigrationTable = Utils::table(MIGRATION_TABLE);
if (!in_array($prefixedMigrationTable, $tables)) {
if (!in_array($prefixedMigrationTable, $tables, true)) {
$pdo->exec('
CREATE TABLE IF NOT EXISTS `' . $prefixedMigrationTable . '` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
......@@ -104,7 +104,6 @@ foreach ($migrations as $migration) {
} else {
$countSkipped++;
}
}
$countTotal = $countSucceeded + $countFailed + $countSkipped;
......
......@@ -21,13 +21,13 @@ use Framadate\Exception\AlreadyExistsException;
use Framadate\Exception\ConcurrentEditionException;
use Framadate\Exception\MomentAlreadyExistsException;
use Framadate\Message;
use Framadate\Security\PasswordHasher;
use Framadate\Services\AdminPollService;
use Framadate\Services\InputService;
use Framadate\Services\LogService;
use Framadate\Services\MailService;
use Framadate\Services\PollService;
use Framadate\Services\NotificationService;
use Framadate\Security\PasswordHasher;
use Framadate\Services\PollService;
use Framadate\Utils;
include_once __DIR__ . '/app/inc/init.php';
......@@ -79,25 +79,25 @@ if (isset($_POST['update_poll_info'])) {
'rules', 'expiration_date', 'name', 'hidden', 'removePassword', 'password']);
// Update the right poll field
if ($field == 'title') {
if ($field === 'title') {
$title = $inputService->filterTitle($_POST['title']);
if ($title) {
$poll->title = $title;
$updated = true;
}
} elseif ($field == 'admin_mail') {
} elseif ($field === 'admin_mail') {
$admin_mail = $inputService->filterMail($_POST['admin_mail']);
if ($admin_mail) {
$poll->admin_mail = $admin_mail;
$updated = true;
}
} elseif ($field == 'description') {
} elseif ($field === 'description') {
$description = $inputService->filterDescription($_POST['description']);
if ($description) {
$poll->description = $description;
$updated = true;
}
} elseif ($field == 'rules') {
} elseif ($field === 'rules') {
$rules = strip_tags($_POST['rules']);
switch ($rules) {
case 0:
......@@ -121,39 +121,39 @@ if (isset($_POST['update_poll_info'])) {
$updated = true;
break;
}
} elseif ($field == 'expiration_date') {
} elseif ($field === 'expiration_date') {
$expiration_date = $inputService->filterDate($_POST['expiration_date']);
if ($expiration_date) {
$poll->end_date = $expiration_date;
$updated = true;
}
} elseif ($field == 'name') {
} elseif ($field === 'name') {
$admin_name = $inputService->filterName($_POST['name']);
if ($admin_name) {
$poll->admin_name = $admin_name;
$updated = true;
}
} elseif ($field == 'hidden') {
} elseif ($field === 'hidden') {
$hidden = isset($_POST['hidden']) ? $inputService->filterBoolean($_POST['hidden']) : false;
if ($hidden != $poll->hidden) {
if ($hidden !== $poll->hidden) {
$poll->hidden = $hidden;
$updated = true;
}
} elseif ($field == 'removePassword') {
} elseif ($field === 'removePassword') {
$removePassword = isset($_POST['removePassword']) ? $inputService->filterBoolean($_POST['removePassword']) : false;
if ($removePassword) {
$poll->results_publicly_visible = false;
$poll->password_hash = null;
$updated = true;
}
} elseif ($field == 'password') {
} elseif ($field === 'password') {
$password = isset($_POST['password']) ? $_POST['password'] : null;
$resultsPubliclyVisible = isset($_POST['resultsPubliclyVisible']) ? $inputService->filterBoolean($_POST['resultsPubliclyVisible']) : false;
if (!empty($password)) {
$poll->password_hash = PasswordHasher::hash($password);
$updated = true;
}
if ($resultsPubliclyVisible != $poll->results_publicly_visible) {
if ($resultsPubliclyVisible !== $poll->results_publicly_visible) {
$poll->results_publicly_visible = $resultsPubliclyVisible;
$updated = true;
}
......@@ -190,11 +190,11 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
if (empty($editedVote)) {
$message = new Message('danger', __('Error', 'Something is going wrong...'));
}
if (count($choices) != count($_POST['choices'])) {
if (count($choices) !== count($_POST['choices'])) {
$message = new Message('danger', __('Error', 'There is a problem with your choices'));
}
if ($message == null) {
if ($message === null) {
// Update vote
try {
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash);
......@@ -212,14 +212,14 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
$slots_hash = $inputService->filterMD5($_POST['control']);
if ($name == null) {
if ($name === null) {
$message = new Message('danger', __('Error', 'The name is invalid.'));
}
if (count($choices) != count($_POST['choices'])) {
if (count($choices) !== count($_POST['choices'])) {
$message = new Message('danger', __('Error', 'There is a problem with your choices'));
}
if ($message == null) {
if ($message === null) {
// Add vote
try {
$result = $pollService->addVote($poll_id, $name, $choices, $slots_hash);
......@@ -401,7 +401,6 @@ $slots = $pollService->allSlotsByPoll($poll);
$votes = $pollService->allVotesByPollId($poll_id);
$comments = $pollService->allCommentsByPollId($poll_id);
// Assign data to template
$smarty->assign('poll_id', $poll_id);
$smarty->assign('admin_poll_id', $admin_poll_id);
......
......@@ -33,7 +33,7 @@ class Choice
public function __construct($name='')
{
$this->name = $name;
$this->slots = array();
$this->slots = [];
}
public function addSlot($slot)
......@@ -55,5 +55,4 @@ class Choice
{
return strcmp($a->name, $b->name);
}
}
......@@ -19,7 +19,6 @@
namespace Framadate;
/**
* Class Editable
*
......
......@@ -2,8 +2,6 @@
namespace Framadate\Exception;
class AlreadyExistsException extends \Exception {
function __construct() {
}
}
......@@ -2,8 +2,6 @@
namespace Framadate\Exception;
class ConcurrentEditionException extends \Exception {
function __construct() {
}
}
......@@ -2,8 +2,6 @@
namespace Framadate\Exception;
class MomentAlreadyExistsException extends \Exception {
function __construct() {
}
}
......@@ -20,7 +20,6 @@ namespace Framadate;
class Form
{
public $title;
public $id;
public $description;
......@@ -87,7 +86,7 @@ class Form
}
public function clearChoices() {
$this->choices = array();
$this->choices = [];
}
public function addChoice(Choice $choice)
......@@ -102,7 +101,6 @@ class Form
public function sortChoices()
{
usort($this->choices, array('Framadate\Choice', 'compare'));
usort($this->choices, ['Framadate\Choice', 'compare']);
}
}
......@@ -18,8 +18,7 @@
*/
namespace Framadate;
class Message {
class Message {
var $type;
var $message;
var $link;
......@@ -27,14 +26,13 @@ class Message {
var $linkIcon;
var $includeTemplate;
function __construct($type, $message, $link=null, $linkTitle=null, $linkIcon=null, $includeTemplate=null) {
function __construct($type, $message, $link=null, $linkTitle=null, $linkIcon=null, $includeTemplate=null) {
$this->type = $type;
$this->message = $message;
$this->link = $link;
$this->linkTitle = $linkTitle;
$this->linkIcon = $linkIcon;
$this->includeTemplate = $includeTemplate;
}
$this->includeTemplate = $includeTemplate;
}
}
\ No newline at end of file
......@@ -27,7 +27,6 @@ use Framadate\Utils;
* @version 0.9
*/
class AddColumn_hidden_In_poll_For_0_9 implements Migration {
function __construct() {
}
......@@ -73,5 +72,4 @@ class AddColumn_hidden_In_poll_For_0_9 implements Migration {
ALTER TABLE `' . Utils::table('poll') . '`
ADD `hidden` TINYINT( 1 ) NOT NULL DEFAULT "0"');
}
}
......@@ -27,7 +27,6 @@ use Framadate\Utils;
* @version 0.9
*/
class AddColumn_receiveNewComments_For_0_9 implements Migration {
function __construct() {
}
......@@ -74,5 +73,4 @@ ALTER TABLE `' . Utils::table('poll') . '`
ADD `receiveNewComments` TINYINT(1) DEFAULT \'0\'
AFTER `receiveNewVotes`');
}
}
......@@ -27,7 +27,6 @@ use Framadate\Utils;
* @version 0.9
*/
class AddColumn_uniqId_In_vote_For_0_9 implements Migration {
function __construct() {
}
......@@ -75,5 +74,4 @@ class AddColumn_uniqId_In_vote_For_0_9 implements Migration {
AFTER `id`,
ADD INDEX (`uniqId`) ;');
}
}
......@@ -27,7 +27,6 @@ use Framadate\Utils;
* @version 0.9
*/
class AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9 implements Migration {
function __construct() {
}
......@@ -74,5 +73,4 @@ class AddColumns_password_hash_And_results_publicly_visible_In_poll_For_0_9 impl
ADD `password_hash` VARCHAR(255) NULL DEFAULT NULL ,
ADD `results_publicly_visible` TINYINT(1) NULL DEFAULT NULL');
}
}
......@@ -27,7 +27,6 @@ use Framadate\Utils;
* @version 1.0
*/
class Alter_Comment_table_adding_date implements Migration {
function __construct() {
}
......@@ -68,5 +67,4 @@ class Alter_Comment_table_adding_date implements Migration {
ALTER TABLE `' . Utils::table('comment') . '`
ADD `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ;');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment