Skip to content

Commit

Permalink
* 1.19 lots of cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc committed Sep 26, 2021
1 parent bcf8105 commit f758ff2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ It's a set of useful functions for PHP. The name is a pun (Mapache in spanish is

[![Build Status](https://travis-ci.org/EFTEC/mapache-commons.svg?branch=master)](https://travis-ci.org/EFTEC/mapache-commons)
[![Packagist](https://img.shields.io/packagist/v/eftec/mapache-commons.svg)](https://packagist.org/packages/eftec/mapache-commons)
[![Maintenance](https://img.shields.io/maintenance/yes/2020.svg)]()
[![Maintenance](https://img.shields.io/maintenance/yes/2021.svg)]()
[![composer](https://img.shields.io/badge/composer-%3E1.6-blue.svg)]()
[![php](https://img.shields.io/badge/php->5.6-green.svg)]()
[![php](https://img.shields.io/badge/php-7.x-green.svg)]()
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "eftec/mapache-commons",
"description": "It's a set of useful functions for PHP. The name is a pun.",
"version": "1.17",
"type": "library",
"keywords": [
"collection",
Expand Down
13 changes: 7 additions & 6 deletions lib/Collection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php /** @noinspection PhpMissingParamTypeInspection */
/** @noinspection PhpMissingReturnTypeInspection */
/** @noinspection ReturnTypeCanBeDeclaredInspection */

/** @noinspection DuplicatedCode */
Expand All @@ -9,7 +10,7 @@
* Class Collection
*
* @package mapache_commons
* @version 1.12 2019-dec-26
* @version 1.19 2021-09-026
* @copyright Jorge Castro Castillo
* @license Apache-2.0
* @see https://github.com/EFTEC/mapache-commons
Expand Down Expand Up @@ -44,7 +45,7 @@ public static function first($array) {
*
* @param array $array input array
*
* @return mixed
* @return int|string|null
* @see https://stackoverflow.com/questions/1921421/get-the-first-element-of-an-array
*/
public static function firstKey($array) {
Expand Down Expand Up @@ -135,9 +136,9 @@ public static function generateTable($array, $css = true) {
$html .= '</tr></thead>';

// data rows
foreach ($array as $key => $value) {
foreach ($array as $value) {
$html .= '<tr >';
foreach ($value as $key2 => $value2) {
foreach ($value as $value2) {
if (is_array($value2)) {
$html .= '<td >' . self::generateTable($value2) . '</td>';
} else {
Expand Down Expand Up @@ -186,7 +187,7 @@ public static function splitOpeningClosing(
$result = [];
// starting.
$even = false;
while ($p0 !== false) {
while (true) {
if (!$even) {
$p1 = strpos($text, $openingTag, $p0);
if ($p1 === false) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Debug.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php /** @noinspection PhpMissingParamTypeInspection */
/** @noinspection PhpMissingReturnTypeInspection */
/** @noinspection UnknownInspectionInspection */

/** @noinspection ReturnTypeCanBeDeclaredInspection */
Expand All @@ -14,7 +15,7 @@
* Class Debug
*
* @package mapache_commons
* @version 1.6 2019-dic.-4 8:38 p. m.
* @version 1.19 2021-09-026
* @copyright Jorge Castro Castillo
* @license Apache-2.0
* @see https://github.com/EFTEC/mapache-commons
Expand All @@ -32,6 +33,7 @@ class Debug {
public static function var_dump($value, $type = 1, $returnValue = false) {
switch ($type) {
case 1:
/** @noinspection JSVoidFunctionReturnValueUsed */
$txt = "<script>console.log(" . json_encode($value) . ");</script>";
break;
case 2:
Expand Down
13 changes: 8 additions & 5 deletions lib/Text.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
<?php /** @noinspection PhpMissingReturnTypeInspection */
/** @noinspection PhpMissingParamTypeInspection */

/** @noinspection ReturnTypeCanBeDeclaredInspection */

namespace mapache_commons;
Expand All @@ -7,7 +9,7 @@
* Class Text
*
* @package mapache_commons
* @version 1.17 2020-06-06
* @version 1.19 2021-09-026
* @copyright Jorge Castro Castillo
* @license Apache-2.0
* @see https://github.com/EFTEC/mapache-commons
Expand Down Expand Up @@ -129,7 +131,7 @@ public static function removeParenthesis($txt, $start = '(', $end = ')') {
* @param null|int $offset the offset position to start the search.
* @param bool $replaceTag If true then it also replaces the tags
*
* @return bool|mixed
* @return array|false|string|string[]
*/
public static function replaceBetween(
$haystack,
Expand Down Expand Up @@ -371,7 +373,7 @@ public static function naturalArg($txt, $separators) {
}
// validation
foreach ($result as $k => $item) {
if ($separators[$k] === 'req' && $result[$k] === null) {
if ($separators[$k] === 'req' && $item === null) {
// it misses one required value.
return null;
}
Expand Down Expand Up @@ -412,7 +414,7 @@ public static function str_replace_ex($search, $replace, $subject,$limit=99999)
* @return bool
*/
public static function wildCardComparison($text,$textWithWildcard) {
if(($textWithWildcard===null && $textWithWildcard==='')
if(($textWithWildcard===null || $textWithWildcard==='')
|| strpos($textWithWildcard,'*')===false) {
// if the text with wildcard is null or empty or it contains two ** or it contains no * then..
return $text==$textWithWildcard;
Expand Down Expand Up @@ -485,6 +487,7 @@ public static function replaceCurlyVariable($string, $values, $notFoundThenKeep
$item = substr($matches[0], 2, -2); // removes {{ and }}
/** @noinspection NestedTernaryOperatorInspection */
/** @noinspection NullCoalescingOperatorCanBeUsedInspection */
/** @noinspection PhpIssetCanBeReplacedWithCoalesceInspection */
return isset($values[$item]) ? $values[$item] : ($notFoundThenKeep ? $matches[0] : '');
}

Expand Down
2 changes: 2 additions & 0 deletions test/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class CollectionTest extends TestCase
{
public function testsplitOpeningClosing()
{
$this->assertEquals(['a','B-C-D','e','F-G-H']
, Collection::splitOpeningClosing("a(B-C-D)e(F-G-H)"));
$this->assertEquals(['a','B,C,D','e','F,G,H']
, Collection::splitOpeningClosing("a(B,C,D)e(F,G,H)"));
$this->assertEquals(['a','(B,C,D)','e','(F,G,H)']
Expand Down

0 comments on commit f758ff2

Please sign in to comment.