Skip to content

Commit

Permalink
Merge branch 'release/2.0.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed May 9, 2019
2 parents 0cf65bd + 1ccce2f commit 404bcfc
Show file tree
Hide file tree
Showing 18 changed files with 145 additions and 55 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v2.0.3
## 05/09/2019

1. [](#new)
* Code cleanup
* Pass `phpstan` tests
* Added `ru` and `uk` translations [#23](https://github.com/getgrav/grav-plugin-problems/pull/23)

# v2.0.2
## 12/16/2018

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Grav Problems Plugin

[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-brightgreen.svg?style=flat)](https://github.com/phpstan/phpstan)

![Problems](assets/readme_1.jpg)

`Problems` is a [Grav](http://github.com/getgrav/grav) Plugin and allows to detect issues.
Expand Down
5 changes: 3 additions & 2 deletions blueprints.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Problems
version: 2.0.2
version: 2.0.3
description: Detects and reports problems found in the site.
icon: exclamation-circle
author:
Expand Down Expand Up @@ -27,7 +27,8 @@ form:

built_in_css:
type: toggle
label: Use built in CSS
label: PLUGIN_PROBLEMS.BUILTIN_CSS
help: PLUGIN_PROBLEMS.BUILTIN_CSS_HELP
highlight: 1
default: 1
options:
Expand Down
7 changes: 4 additions & 3 deletions classes/Problems/Apache.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems;

use Grav\Plugin\Problems\Base\Problem;
Expand All @@ -18,16 +19,16 @@ public function __construct()
public function process()
{
// Perform some Apache checks
if (strpos(php_sapi_name(), 'apache') !== false && function_exists('apache_get_modules')) {
if (function_exists('apache_get_modules') && strpos(PHP_SAPI, 'apache') !== false) {

$require_apache_modules = ['mod_rewrite'];
$apache_modules = apache_get_modules();

$apache_errors = [];
$apache_success = [];

foreach ((array) $require_apache_modules as $module) {
if (in_array($module, $apache_modules)) {
foreach ($require_apache_modules as $module) {
if (in_array($module, $apache_modules, true)) {
$apache_success[$module] = 'module required but not enabled';
} else {
$apache_errors[$module] = 'module is not installed or enabled';
Expand Down
34 changes: 18 additions & 16 deletions classes/Problems/Base/Problem.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems\Base;

class Problem implements \JsonSerializable
Expand All @@ -16,38 +17,38 @@ class Problem implements \JsonSerializable
protected $help;
protected $class;

public function __contstruct($data = null)
public function load($data)
{
if (!is_null($data)) {
$this->load($data);
}
}

public function load($data) {
$this->set_object_vars($data);
}

public function process() {
public function process()
{
return $this;
}

public function getId() {
public function getId()
{
return $this->id;
}

public function getOrder() {
public function getOrder()
{
return $this->order;
}

public function getLevel() {
public function getLevel()
{
return $this->level;
}

public function getStatus() {
public function getStatus()
{
return $this->status;
}

public function getMsg() {
public function getMsg()
{
return $this->msg;
}

Expand Down Expand Up @@ -76,10 +77,11 @@ public function jsonSerialize()
$this->toArray();
}

protected function set_object_vars($object, array $vars) {
$has = get_object_vars($object);
protected function set_object_vars(array $vars)
{
$has = get_object_vars($this);
foreach ($has as $name => $oldValue) {
$object->$name = isset($vars[$name]) ? $vars[$name] : NULL;
$this->{$name} = isset($vars[$name]) ? $vars[$name] : NULL;
}
}
}
15 changes: 13 additions & 2 deletions classes/Problems/Base/ProblemChecker.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems\Base;

use Grav\Common\Cache;
Expand All @@ -23,14 +24,19 @@ public function __construct()
public function load()
{
if ($this->statusFileExists()) {
$json = file_get_contents($this->status_file);
$json = file_get_contents($this->status_file) ?: '';
$data = json_decode($json, true);
if (!is_array($data)) {
return false;
}

foreach ($data as $problem) {
$class = $problem['class'];
$this->problems[] = new $class($problem);
}
}

return true;
}

public function getStatusFile()
Expand All @@ -51,8 +57,9 @@ public function storeStatusFile()
file_put_contents($this->status_file, $json);
}

public function check($problems_dir)
public function check($problems_dir = null)
{
$problems_dir = $problems_dir ?: dirname(__DIR__);
$problems = [];
$problems_found = false;

Expand All @@ -71,6 +78,8 @@ public function check($problems_dir)

// Get the problems in order
usort($problems, function($a, $b) {
/** @var Problem $a */
/** @var Problem $b */
return $b->getOrder() - $a->getOrder();
});

Expand All @@ -97,6 +106,8 @@ public function getProblems()

// Put the failed ones first
usort($problems, function($a, $b) {
/** @var Problem $a */
/** @var Problem $b */
return $a->getStatus() - $b->getStatus();
});

Expand Down
1 change: 1 addition & 0 deletions classes/Problems/EssentialFolders.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems;

use Grav\Plugin\Problems\Base\Problem;
Expand Down
23 changes: 12 additions & 11 deletions classes/Problems/PHPModules.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems;

use Grav\Common\Grav;
Expand All @@ -22,38 +23,38 @@ public function process()
$modules_success = [];

// Check for PHP CURL library
$msg = "PHP Curl (Data Transfer Library) is %s installed";
$msg = 'PHP Curl (Data Transfer Library) is %s installed';
if (function_exists('curl_version')) {
$modules_success['curl'] = sprintf($msg, 'successfully');
} else {
$modules_errors['curl'] = sprintf($msg, 'required but not');
}

// Check for PHP Ctype library
$msg = "PHP Ctype is %s installed";
$msg = 'PHP Ctype is %s installed';
if (function_exists('ctype_print')) {
$modules_success['ctype'] = sprintf($msg, 'successfully');
} else {
$modules_errors['ctype'] = sprintf($msg, 'required but not');
}

// Check for PHP Dom library
$msg = "PHP DOM is %s installed";
$msg = 'PHP DOM is %s installed';
if (class_exists('DOMDocument')) {
$modules_success['dom'] = sprintf($msg, 'successfully');
} else {
$modules_errors['dom'] = sprintf($msg, 'required but not');
}

// Check for GD library
$msg = "PHP GD (Image Manipulation Library) is %s installed";
$msg = 'PHP GD (Image Manipulation Library) is %s installed';
if (defined('GD_VERSION') && function_exists('gd_info')) {

$msg = $modules_success['gd'] = sprintf($msg, 'successfully');

// Extra checks for Image support
$ginfo = gd_info();
$gda = array("PNG Support", "JPEG Support", "FreeType Support", "GIF Read Support");
$gda = array('PNG Support', 'JPEG Support', 'FreeType Support', 'GIF Read Support');
$gda_msg = '';
$problems_found = false;

Expand All @@ -75,31 +76,31 @@ public function process()
}

// Check for PHP MbString library
$msg = "PHP Mbstring (Multibyte String Library) is %s installed";
$msg = 'PHP Mbstring (Multibyte String Library) is %s installed';
if (extension_loaded('mbstring')) {
$modules_success['mbstring'] = sprintf($msg, 'successfully');
} else {
$modules_errors['mbstring'] = sprintf($msg, 'required but not');
}

// Check for PHP Open SSL library
$msg = "PHP OpenSSL (Secure Sockets Library) is %s installed";
if (extension_loaded('openssl') && defined('OPENSSL_VERSION_TEXT')) {
$msg = 'PHP OpenSSL (Secure Sockets Library) is %s installed';
if (defined('OPENSSL_VERSION_TEXT') && extension_loaded('openssl')) {
$modules_success['openssl'] = sprintf($msg, 'successfully');
} else {
$modules_errors['openssl'] = sprintf($msg, 'required but not');
}

// Check for PHP XML library
$msg = "PHP XML Library is %s installed";
$msg = 'PHP XML Library is %s installed';
if (extension_loaded('xml')) {
$modules_success['xml'] = sprintf($msg, 'successfully');
} else {
$modules_errors['xml'] = sprintf($msg, 'required but not');
}

// Check for PHP Zip library
$msg = "PHP Zip extension is %s installed";
$msg = 'PHP Zip extension is %s installed';
if (extension_loaded('zip')) {
$modules_success['zip'] = sprintf($msg, 'successfully');
} else {
Expand All @@ -108,7 +109,7 @@ public function process()

// Check Exif if enabled
if (Grav::instance()['config']->get('system.media.auto_metadata_exif')) {
$msg = "PHP Exif (Exchangeable Image File Format) is %s installed";
$msg = 'PHP Exif (Exchangeable Image File Format) is %s installed';
if (extension_loaded('exif')) {
$modules_success['exif'] = sprintf($msg, 'successfully');
} else {
Expand Down
5 changes: 3 additions & 2 deletions classes/Problems/PHPVersion.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems;

use Grav\Plugin\Problems\Base\Problem;
Expand All @@ -18,9 +19,9 @@ public function __construct()
public function process()
{
$min_php_version = defined('GRAV_PHP_MIN') ? GRAV_PHP_MIN : '5.6.4';
$your_php_version = phpversion();
$your_php_version = PHP_VERSION;

$msg = "Your PHP <strong>%s</strong> is %s than the minimum of <strong>%s</strong> required";
$msg = 'Your PHP <strong>%s</strong> is %s than the minimum of <strong>%s</strong> required';

// Check PHP version
if (version_compare($your_php_version, $min_php_version, '<')) {
Expand Down
3 changes: 2 additions & 1 deletion classes/Problems/Permissions.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Grav\Plugin\Problems;

use Grav\Plugin\Problems\Base\Problem;
Expand All @@ -19,7 +20,7 @@ public function process()
{
umask($umask = umask(022));

$msg = "Your default file umask is <strong>%s</strong> which %s";
$msg = 'Your default file umask is <strong>%s</strong> which %s';

if (($umask & 2) !== 2) {
$this->msg = sprintf($msg, decoct($umask), 'is potentially dangerous');
Expand Down
19 changes: 8 additions & 11 deletions cli/CheckCommand.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace Grav\Plugin\Console;

use Grav\Common\Grav;
use Grav\Console\ConsoleCommand;
use Grav\Plugin\Problems\Base\Problem;
use Grav\Plugin\Problems\Base\ProblemChecker;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableSeparator;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
Expand All @@ -17,14 +17,11 @@
*/
class CheckCommand extends ConsoleCommand
{
/**
*
*/
protected function configure()
{
$this
->setName("check")
->setDescription("Check Problems")
->setName('check')
->setDescription('Check Problems')
->setHelp('The <info>problems command</info> allows you display any potential problems with your Grav setup')
;
}
Expand All @@ -34,10 +31,9 @@ protected function configure()
*/
protected function serve()
{
/** @var use new SymfonyStyle helper $io */
$io = new SymfonyStyle($this->input, $this->output);

$plugin_dir = realpath(__DIR__ . '/..');
$plugin_dir = realpath(dirname(__DIR__));
$problems_dir = $plugin_dir . '/classes/Problems';

require $plugin_dir . '/vendor/autoload.php';
Expand All @@ -54,13 +50,14 @@ protected function serve()
$headers = ['ID', 'Status', 'Level', 'Message'];
$rows = [];

/** @var Problem $problem */
foreach ($problems as $problem) {
$rows[] = new TableSeparator();

$rows[] = [
$problem->getStatus() ? $problem->getID() : '<red>' . $problem->getId() . '</red>' ,
$problem->getStatus() ? $problem->getId() : '<red>' . $problem->getId() . '</red>' ,
$problem->getStatus() ? '<green>success</green>' : '<red>error</red>',
$problem->getLevel() == 'critical' ? '<red>' . $problem->getLevel() . '</red>' : '<yellow>' .$problem->getLevel() . '</yellow>',
$problem->getLevel() === 'critical' ? '<red>' . $problem->getLevel() . '</red>' : '<yellow>' .$problem->getLevel() . '</yellow>',
strip_tags($problem->getMsg()),
];

Expand Down
Loading

0 comments on commit 404bcfc

Please sign in to comment.