Skip to content

Commit

Permalink
Fixing some PSR-2 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Alanaktion committed Aug 6, 2018
1 parent e24c8dc commit 1522061
Show file tree
Hide file tree
Showing 18 changed files with 34 additions and 56 deletions.
1 change: 0 additions & 1 deletion app/controller/admin.php
Expand Up @@ -376,7 +376,6 @@ public function user_save(\Base $f3)

// Save user
$user->save();

} catch (\Exception $e) {
$f3->set("error", $e->getMessage());
$this->_render("admin/users/edit.html");
Expand Down
1 change: 0 additions & 1 deletion app/controller/api/issues.php
Expand Up @@ -114,7 +114,6 @@ public function post($f3)
// By default, use standard HTTP POST fields
$post = $_REQUEST;
} else {

// For Redmine compatibility, also accept a JSON object
try {
$post = json_decode(file_get_contents('php://input'), true);
Expand Down
16 changes: 8 additions & 8 deletions app/controller/api/user.php
Expand Up @@ -67,10 +67,10 @@ public function get($f3)

$user = new \Model\User;
$result = $user->paginate(
$f3->get("GET.offset") / $pagLimit,
$pagLimit,
"deleted_date IS NULL AND role != 'group'"
);
$f3->get("GET.offset") / $pagLimit,
$pagLimit,
"deleted_date IS NULL AND role != 'group'"
);

$users = array();
foreach ($result["subset"] as $user) {
Expand Down Expand Up @@ -99,10 +99,10 @@ public function get_group($f3)

$user = new \Model\User;
$result = $user->paginate(
$f3->get("GET.offset") / $pagLimit,
$pagLimit,
"deleted_date IS NULL AND role = 'group' AND api_visible != '0'"
);
$f3->get("GET.offset") / $pagLimit,
$pagLimit,
"deleted_date IS NULL AND role = 'group' AND api_visible != '0'"
);

$groups = array();
foreach ($result["subset"] as $user) {
Expand Down
2 changes: 0 additions & 2 deletions app/controller/files.php
Expand Up @@ -191,7 +191,6 @@ public function avatar($f3, $params)
$user->load($params["id"]);

if ($user->avatar_filename && is_file("uploads/avatars/" . $user->avatar_filename)) {

// Use local file
$img = new \Image($user->avatar_filename, null, "uploads/avatars/");
$img->resize($params["size"], $params["size"]);
Expand All @@ -201,7 +200,6 @@ public function avatar($f3, $params)
header("Cache-Control: private, max-age=" . (3600 / 2));
$img->render($params["format"]);
} else {

// Send user to Gravatar
header("Cache-Control: max-age=" . (3600 * 24));
$f3->reroute($f3->get("SCHEME") . ":" . \Helper\View::instance()->gravatar($user->email, $params["size"]), true);
Expand Down
1 change: 0 additions & 1 deletion app/controller/index.php
Expand Up @@ -81,7 +81,6 @@ public function loginpost($f3)
// Verify password
$security = \Helper\Security::instance();
if ($security->hashEquals($security->hash($f3->get("POST.password"), $user->salt ?: ""), $user->password)) {

// Create a session and use it
$session = new \Model\Session($user->id);
$session->setCurrent();
Expand Down
12 changes: 4 additions & 8 deletions app/controller/issues.php
Expand Up @@ -234,9 +234,8 @@ public function bulk_update($f3)
}

// Diff contents and save what's changed.
foreach ($post as $i=>$val) {
if (
$issue->exists($i)
foreach ($post as $i => $val) {
if ($issue->exists($i)
&& $i != "id"
&& $issue->$i != $val
&& (!empty($val) || $val === "0")
Expand Down Expand Up @@ -558,9 +557,8 @@ protected function _saveUpdate()

// Diff contents and save what's changed.
$hashState = json_decode($post["hash_state"]);
foreach ($post as $i=>$val) {
if (
$issue->exists($i)
foreach ($post as $i => $val) {
if ($issue->exists($i)
&& $i != "id"
&& $issue->$i != $val
&& md5($val) != $hashState->$i
Expand Down Expand Up @@ -645,7 +643,6 @@ protected function _saveNew()
public function save($f3)
{
if ($f3->get("POST.id")) {

// Updating existing issue.
$issue = $this->_saveUpdate();
if ($issue->id) {
Expand All @@ -654,7 +651,6 @@ public function save($f3)
$f3->error(404, "This issue does not exist.");
}
} elseif ($f3->get("POST.name")) {

// Creating new issue.
$issue = $this->_saveNew();
if ($issue->id) {
Expand Down
3 changes: 1 addition & 2 deletions app/controller/issues/project.php
Expand Up @@ -61,8 +61,7 @@ public function overview($f3, $params)
* @param int $level
* @var callable $renderTree This function, required for recursive calls
*/
$renderTree = function (\Model\Issue &$issue, $level = 0) use ($parentMap, &$renderTree)
{
$renderTree = function (\Model\Issue &$issue, $level = 0) use ($parentMap, &$renderTree) {
if ($issue->id) {
$f3 = \Base::instance();
$children = $parentMap[$issue->id] ?: [];
Expand Down
1 change: 0 additions & 1 deletion app/controller/taskboard.php
Expand Up @@ -187,7 +187,6 @@ public function index($f3, $params)
// Build multidimensional array of all tasks and projects
$taskboard = array();
foreach ($projects as $project) {

// Build array of statuses to put tasks under
$columns = array();
foreach ($statuses as $status) {
Expand Down
10 changes: 4 additions & 6 deletions app/controller/user.php
Expand Up @@ -46,8 +46,8 @@ public function dashboard($f3)
// Load dashboard widget data
$allWidgets = $helper->allWidgets;
$missing = array();
foreach ($dashboard as $k=>$widgets) {
foreach ($widgets as $l=>$widget) {
foreach ($dashboard as $k => $widgets) {
foreach ($widgets as $l => $widget) {
if (in_array($widget, $allWidgets)) {
$f3->set($widget, $helper->$widget());
} else {
Expand Down Expand Up @@ -171,13 +171,11 @@ public function save($f3)
$f3->set("error", "Current password entered is not valid.");
}
} elseif (!empty($post["action"]) && $post["action"] == "options") {

// Update option values
$user->option("disable_mde", !empty($post["disable_mde"]));
$user->option("disable_due_alerts", !empty($post["disable_due_alerts"]));
$user->option("disable_self_notifications", !empty($post["disable_self_notifications"]));
} else {

// Update profile
if (!empty($post["name"])) {
$user->name = filter_var($post["name"], FILTER_SANITIZE_STRING);
Expand Down Expand Up @@ -330,13 +328,13 @@ public function single($f3, $params)
0,
200,
array("status_closed = '0' AND deleted_date IS NULL AND author_id = ?", $user->id),
array("order" => "priority DESC, due_date DESC")
array("order" => "priority DESC, due_date DESC")
));
$f3->set("assigned_issues", $issue->paginate(
0,
200,
array("status_closed = '0' AND deleted_date IS NULL AND owner_id = ?", $user->id),
array("order" => "priority DESC, due_date DESC")
array("order" => "priority DESC, due_date DESC")
));
$f3->set("overdue_issues", $issue->paginate(0, 200, array("status_closed = '0' AND deleted_date IS NULL AND owner_id = ? AND due_date IS NOT NULL AND due_date < ?",
$user->id, date("Y-m-d", \Helper\View::instance()->utc2local())), array("order" => "due_date ASC")));
Expand Down
2 changes: 1 addition & 1 deletion app/helper/dashboard.php
Expand Up @@ -66,7 +66,7 @@ public function subprojects()

$projects = $this->_projects;
$subprojects = array();
foreach ($projects as $i=>$project) {
foreach ($projects as $i => $project) {
if ($project->parent_id) {
$subprojects[] = $project;
unset($projects[$i]);
Expand Down
2 changes: 1 addition & 1 deletion app/helper/file.php
Expand Up @@ -45,7 +45,7 @@ class File extends \Image
*/
public static function mimeIcon($contentType)
{
foreach (self::$mimeMap["icon"] as $regex=>$name) {
foreach (self::$mimeMap["icon"] as $regex => $name) {
if (preg_match("@^" . $regex . "$@i", $contentType)) {
return $name;
}
Expand Down
4 changes: 2 additions & 2 deletions app/helper/matrix.php
Expand Up @@ -14,13 +14,13 @@ class Matrix extends \Matrix
public function mergeSorted(array $arrays)
{
$lengths = array();
foreach ($arrays as $k=>$v) {
foreach ($arrays as $k => $v) {
$lengths[$k] = count($v);
}
$max = max($lengths);
$result = array();
for ($i = 0; $i < $max; $i++) {
foreach ($lengths as $k=>$l) {
foreach ($lengths as $k => $l) {
if ($l > $i) {
$result[] = $arrays[$k][$i];
}
Expand Down
15 changes: 5 additions & 10 deletions app/helper/notification.php
Expand Up @@ -35,10 +35,8 @@ public function quotePrintEncode($str)
|| (ord($c) == 0x7f)
|| (ord($c) & 0x80)
|| ($c == '=')
|| (($c == ' ') && ($str[$str_index] == "\015")))
{
if (($lp += 3) > self::QPRINT_MAXL)
{
|| (($c == ' ') && ($str[$str_index] == "\015"))) {
if (($lp += 3) > self::QPRINT_MAXL) {
$ret .= '=';
$ret .= "\015";
$ret .= "\012";
Expand All @@ -47,18 +45,15 @@ public function quotePrintEncode($str)
$ret .= '=';
$ret .= $hex[ord($c) >> 4];
$ret .= $hex[ord($c) & 0xf];
}
else
{
if ((++$lp) > self::QPRINT_MAXL)
{
} else {
if ((++$lp) > self::QPRINT_MAXL) {
$ret .= '=';
$ret .= "\015";
$ret .= "\012";
$lp = 1;
}
$ret .= $c;
if($lp == 1 && $c == '.') {
if ($lp == 1 && $c == '.') {
$ret = substr($ret, 0, strlen($ret) - 1);
$ret .= '=2E';
$lp++;
Expand Down
6 changes: 2 additions & 4 deletions app/helper/plugin.php
Expand Up @@ -126,8 +126,7 @@ public function getJsFiles($path = null)
{
$return = array();
foreach ($this->_jsFiles as $item) {
if (
!$item['match'] || !$path ||
if (!$item['match'] || !$path ||
($item['match'] && $path && preg_match($item['match'], $path))
) {
$return[] = $item['file'];
Expand All @@ -145,8 +144,7 @@ public function getJsCode($path = null)
{
$return = array();
foreach ($this->_jsCode as $item) {
if (
!$item['match'] || !$path ||
if (!$item['match'] || !$path ||
($item['match'] && $path && preg_match($item['match'], $path))
) {
$return[] = $item['code'];
Expand Down
6 changes: 3 additions & 3 deletions app/helper/update.php
Expand Up @@ -22,13 +22,13 @@ public function humanReadableValues($field, $old_val, $new_val)
if (is_callable(array($this, $func))) {
if ($old_val !== null && $old_val !== '') {
$old_val = call_user_func_array(
array($this, $func),
array($this, $func),
array($old_val)
);
}
if ($new_val !== null && $new_val !== '') {
$new_val = call_user_func_array(
array($this, $func),
array($this, $func),
array($new_val)
);
}
Expand All @@ -38,7 +38,7 @@ public function humanReadableValues($field, $old_val, $new_val)
$name = $f3->get("dict.cols." . $field);
if ($name === null) {
$name = ucwords(str_replace(
array("_", " id"),
array("_", " id"),
array(" ", ""),
$field
));
Expand Down
4 changes: 2 additions & 2 deletions app/helper/view.php
Expand Up @@ -222,12 +222,12 @@ protected function _parseEmoticons($str)
'8O' => "\xF0\x9F\x98\xB2", // oops
];

$match = implode('|', array_map(function($str) {
$match = implode('|', array_map(function ($str) {
return preg_quote($str, '/');
}, array_keys($map)));
$regex = "/([^a-z\\/&]|^)($match)([^a-z\\/]|$)/m";

return preg_replace_callback($regex, function($match) use ($map) {
return preg_replace_callback($regex, function ($match) use ($map) {
return $match[1] . $map[$match[2]] . $match[3];
}, $str);
}
Expand Down
2 changes: 1 addition & 1 deletion app/model.php
Expand Up @@ -103,7 +103,7 @@ public function delete()
* @param integer $ttl
* @return mixed
*/
public function load($filter=null, array $options=null, $ttl=0)
public function load($filter = null, array $options = null, $ttl = 0)
{
if (is_numeric($filter)) {
return parent::load(array("id = ?", $filter), $options, $ttl);
Expand Down
2 changes: 0 additions & 2 deletions app/model/issue.php
Expand Up @@ -373,7 +373,6 @@ public function save($notify = true)

// Check if updating or inserting
if ($this->query) {

// Save issue updates and send notifications
$update = $this->_saveUpdate($notify);
$issue = parent::save();
Expand All @@ -382,7 +381,6 @@ public function save($notify = true)
$notification->issue_update($this->id, $update->id);
}
} else {

// Set closed date if status is closed
if (!$this->closed_date && $this->status) {
$status = new Issue\Status;
Expand Down

0 comments on commit 1522061

Please sign in to comment.