Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update files #78

Merged
merged 18 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/RequirementsChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
use function intval;

/**
* YiiRequirementChecker allows checking, if current system meets the requirements for running the Yii application.
* RequirementChecker allows checking, if current system meets the requirements for running the Yii application.
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
* This class allows rendering of the check report for the web and console application interface.
*
* Example:
*
* ```php
* require_once 'path/to/YiiRequirementChecker.php';
* $requirementsChecker = new YiiRequirementChecker();
*
* require_once('vendor/yiisoft/requirements/src/RequirementsChecker.php');
* use Yiisoft\Requirements\RequirementsChecker;
* $requirementsChecker = new RequirementsChecker;
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
* $requirements = [
* [
* 'name' => 'PHP Some Extension',
Expand Down Expand Up @@ -99,7 +101,7 @@
if (!$requirement['condition']) {
if ($requirement['mandatory']) {
$requirement['error'] = true;
$requirement['warning'] = true;

Check warning on line 104 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": --- Original +++ New @@ @@ if (!$requirement['condition']) { if ($requirement['mandatory']) { $requirement['error'] = true; - $requirement['warning'] = true; + $requirement['warning'] = false; $this->result['summary']['errors']++; } else { $requirement['error'] = false;
$this->result['summary']['errors']++;
} else {
$requirement['error'] = false;
Expand Down Expand Up @@ -179,7 +181,7 @@
if (empty($extensionVersion)) {
return false;
}
if (strncasecmp($extensionVersion, 'PECL-', 5) === 0) {

Check warning on line 184 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ if (empty($extensionVersion)) { return false; } - if (strncasecmp($extensionVersion, 'PECL-', 5) === 0) { + if (strncasecmp($extensionVersion, 'PECL-', 4) === 0) { $extensionVersion = substr($extensionVersion, 5); } /** @var bool */

Check warning on line 184 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ if (empty($extensionVersion)) { return false; } - if (strncasecmp($extensionVersion, 'PECL-', 5) === 0) { + if (strncasecmp($extensionVersion, 'PECL-', 6) === 0) { $extensionVersion = substr($extensionVersion, 5); } /** @var bool */

Check warning on line 184 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ if (empty($extensionVersion)) { return false; } - if (strncasecmp($extensionVersion, 'PECL-', 5) === 0) { + if (strncasecmp($extensionVersion, 'PECL-', 5) === -1) { $extensionVersion = substr($extensionVersion, 5); } /** @var bool */
$extensionVersion = substr($extensionVersion, 5);
}

Expand Down Expand Up @@ -248,7 +250,7 @@
return (int) $verboseSize;
}
$sizeUnit = trim($verboseSize, '0123456789');
$size = trim(str_replace($sizeUnit, '', $verboseSize));

Check warning on line 253 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "UnwrapTrim": --- Original +++ New @@ @@ return (int) $verboseSize; } $sizeUnit = trim($verboseSize, '0123456789'); - $size = trim(str_replace($sizeUnit, '', $verboseSize)); + $size = str_replace($sizeUnit, '', $verboseSize); if (!is_numeric($size)) { return 0; }
if (!is_numeric($size)) {
return 0;
}
Expand Down Expand Up @@ -313,7 +315,7 @@
/**
* @psalm-suppress InvalidArgument Need for compatibility with PHP 7.4
*/
PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(0);
PHP_VERSION_ID >= 80000 ? ob_implicit_flush(false) : ob_implicit_flush(false);
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved

/** @psalm-suppress UnresolvableInclude */
require $_viewFile_;
Expand All @@ -333,7 +335,7 @@
* @param int|string $requirementKey Requirement key in the list.
* @return array Normalized requirement.
*/
public function normalizeRequirement(array $requirement, $requirementKey = 0): array

Check warning on line 338 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ * @param int|string $requirementKey Requirement key in the list. * @return array Normalized requirement. */ - public function normalizeRequirement(array $requirement, $requirementKey = 0) : array + public function normalizeRequirement(array $requirement, $requirementKey = -1) : array { if (!array_key_exists('condition', $requirement)) { $this->usageError("Requirement \"{$requirementKey}\" has no condition!");

Check warning on line 338 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ * @param int|string $requirementKey Requirement key in the list. * @return array Normalized requirement. */ - public function normalizeRequirement(array $requirement, $requirementKey = 0) : array + public function normalizeRequirement(array $requirement, $requirementKey = 1) : array { if (!array_key_exists('condition', $requirement)) { $this->usageError("Requirement \"{$requirementKey}\" has no condition!");

Check warning on line 338 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "PublicVisibility": --- Original +++ New @@ @@ * @param int|string $requirementKey Requirement key in the list. * @return array Normalized requirement. */ - public function normalizeRequirement(array $requirement, $requirementKey = 0) : array + protected function normalizeRequirement(array $requirement, $requirementKey = 0) : array { if (!array_key_exists('condition', $requirement)) { $this->usageError("Requirement \"{$requirementKey}\" has no condition!");
{
if (!array_key_exists('condition', $requirement)) {
$this->usageError("Requirement \"$requirementKey\" has no condition!");
Expand All @@ -354,10 +356,10 @@
$requirement['mandatory'] = false;
}
}
if (!array_key_exists('by', $requirement)) {

Check warning on line 359 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ $requirement['mandatory'] = false; } } - if (!array_key_exists('by', $requirement)) { + if (array_key_exists('by', $requirement)) { $requirement['by'] = 'Unknown'; } if (!array_key_exists('memo', $requirement)) {
$requirement['by'] = 'Unknown';
}
if (!array_key_exists('memo', $requirement)) {

Check warning on line 362 in src/RequirementsChecker.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.3-ubuntu-latest

Escaped Mutant for Mutator "LogicalNot": --- Original +++ New @@ @@ if (!array_key_exists('by', $requirement)) { $requirement['by'] = 'Unknown'; } - if (!array_key_exists('memo', $requirement)) { + if (array_key_exists('memo', $requirement)) { $requirement['memo'] = ''; } return $requirement;
$requirement['memo'] = '';
}

Expand Down Expand Up @@ -402,6 +404,10 @@
*/
public function getNowDate(): string
{
return @strftime('%Y-%m-%d %H:%M', time());
// DEPRECATED as of PHP 8.1.0. Relying on this function is highly discouraged.
// https://www.php.net/manual/en/function.strftime.php
// return @strftime('%Y-%m-%d %H:%M', time());

luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
return date("Y-m-d H:i:s", time());
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
}
}
14 changes: 8 additions & 6 deletions src/views/console/index.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?php

/**
* @var Yiisoft\Requirements\RequirementsChecker $this
* @var array $summary
* @var array[] $requirements
*/
/* @var $this Yiisoft\Requirements\RequirementsChecker */
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
/* @var $summary array */
/* @var $requirements array[] */

echo "\nRequirements Checker\n\n";

Expand All @@ -20,12 +18,16 @@
foreach ($requirements as $key => $requirement) {
if ($requirement['condition']) {
echo $requirement['name'] . ": OK\n";
$memo = strip_tags($requirement['memo']);
if (!empty($memo)) {
echo strip_tags($requirement['memo']) . "\n";
luizcmarin marked this conversation as resolved.
Show resolved Hide resolved
}
} else {
echo $requirement['name'] . ': ' . ($requirement['mandatory'] ? 'FAILED!!!' : 'WARNING!!!') . "\n";
echo 'Required by: ' . strip_tags($requirement['by']) . "\n";
$memo = strip_tags($requirement['memo']);
if (!empty($memo)) {
echo 'Memo: ' . strip_tags($requirement['memo']) . "\n";
echo strip_tags($requirement['memo']) . "\n";
}
}
echo "\n";
Expand Down
Loading
Loading