Skip to content

Commit

Permalink
Improves CS. Updates composer to v2.*
Browse files Browse the repository at this point in the history
  • Loading branch information
flobee committed Jul 7, 2021
1 parent 03b4de6 commit 528c2a3
Show file tree
Hide file tree
Showing 12 changed files with 1,507 additions and 723 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": "7.2.* || 7.3.* || 7.4.*",
"tedivm/jshrink": "*",
"phpunit/phpunit": "^6",
"composer/composer": "^1.9",
"composer/composer": "^2",
"squizlabs/php_codesniffer": "^3.5",
"phpstan/phpstan": "^0.11.19",
"phpbench/phpbench": "^0.16.10"
Expand Down
2,010 changes: 1,416 additions & 594 deletions composer.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/Mumsys_Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,9 @@ public function getGeneric( $interface, $default = null )
}
catch ( Exception $e ) {
if ( $default === null ) {
$message = sprintf( 'Generic interface "%1$s" not found. Message: "%2$s"', $interface, $e->getMessage() );
$message = sprintf(
'Generic interface "%1$s" not found. Message: "%2$s"', $interface, $e->getMessage()
);
throw new Mumsys_Exception( $message );
} else {
$return = $default;
Expand Down
23 changes: 9 additions & 14 deletions src/Mumsys_FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public function __construct( array $args = array() )
*
* @return array|false Returns list of file/link/directory details like path, name, size, type
*/
public function scanDirInfo( $dir, $hideHidden = true, $recursive = false, array $filters = array(), $offset = 0, $limit = 0 )
public function scanDirInfo( $dir, $hideHidden = true, $recursive = false,
array $filters = array(), $offset = 0, $limit = 0 )
{
if ( $offset < 0 ) {
$offset = 0;
Expand All @@ -84,8 +85,7 @@ public function scanDirInfo( $dir, $hideHidden = true, $recursive = false, array
if ( @is_dir( $dir ) && is_readable( $dir ) && !is_link( $dir ) ) {
$cnt=0;
if ( $dh = @opendir( $dir ) ) {
while( ( $file = readdir( $dh ) ) !== false )
{
while ( ( $file = readdir( $dh ) ) !== false ) {
if ( $file=='.' || $file=='..' ) {
continue;
}
Expand All @@ -99,8 +99,7 @@ public function scanDirInfo( $dir, $hideHidden = true, $recursive = false, array
$newdir = $dir . $ds . $file;
$this->_dirInfo[$newdir] = $this->getFileDetails( $newdir );
$this->scanDirInfo( $newdir, $hideHidden, $recursive, $filters, $offset, $limit );
}
else {
} else {
$this->_dirInfo[$test] = $this->getFileDetails( $dir, $file );
$cnt++;
}
Expand All @@ -112,7 +111,7 @@ public function scanDirInfo( $dir, $hideHidden = true, $recursive = false, array
}

if ( $filters ) {
foreach( $this->_dirInfo as $location => & $none ) {
foreach ( $this->_dirInfo as $location => & $none ) {
foreach ( $filters as $regex ) {
if ( !preg_match( $regex, $location ) ) {
unset( $this->_dirInfo[$location] );
Expand Down Expand Up @@ -161,8 +160,7 @@ private function _getFileDetailsPrepare( $fileOrPath, $filename = false )
if ( !$path ) {
$path = substr( $filepath, 0, strrpos( $filepath, '/' ) );
}
}
else {
} else {
throw new Mumsys_FileSystem_Exception( 'File "' . $filepath . '" not found' );
}

Expand Down Expand Up @@ -248,8 +246,7 @@ public function getFileDetailsExtended( $file, $filename = false )
$file = $prepared['file'];
$info = array();

if ( $stat = @lstat( $path . '/' . $filename ) )
{
if ( $stat = @lstat( $path . '/' . $filename ) ) {
$info = array(
'file' => $prepared['file'],
'type' => filetype( $file ),
Expand Down Expand Up @@ -417,8 +414,7 @@ public function rename( $source, $destination, $keepCopy = true, $streamContext
// }
// }

if ( is_file( $source ) )
{
if ( is_file( $source ) ) {
if ( $keepCopy && file_exists( $destination ) ) {
$destination = $this->copy( $source, $destination, $keepCopy );
}
Expand Down Expand Up @@ -671,8 +667,7 @@ public function rmdirs( $basePath )
try
{
$iterator = new DirectoryIterator( $basePath );
foreach ( $iterator as $fileinfo )
{
foreach ( $iterator as $fileinfo ) {
if ( $fileinfo->isDot() ) {
continue;
}
Expand Down
44 changes: 16 additions & 28 deletions src/Mumsys_GetOpts.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,21 +162,18 @@ public function __construct( array $options = array( ), array $input = null )
$errorNotice = '';
$unflag = array();

while ( $argPos < $argc )
{
while ( $argPos < $argc ) {
$arg = $argv[$argPos];

// skip values as they are expected in argPos + 1, if any
if ( isset( $arg[0] ) && $arg[0] == '-' )
{
if ( isset( $arg[0] ) && $arg[0] == '-' ) {
if ( $arg[1] == '-' ) {
$argTag = '--' . substr( $arg, 2, strlen( $arg ) );
} else {
$argTag = '-' . $arg[1]; // take the short flag
}

if ( !isset( $map[ $argTag ] ) )
{
if ( !isset( $map[ $argTag ] ) ) {
// a --no-FLAG' to unset?
$test = substr( $argTag, 5, strlen( $argTag ) );
if ( strlen( $test )==1 ) {
Expand All @@ -199,22 +196,18 @@ public function __construct( array $options = array( ), array $input = null )
$var = $map[ $argTag ];
}

foreach ( $options as $_opk => $_opv )
{
foreach ( $options as $_opk => $_opv ) {
if ( is_string( $_opk ) ) {
$_opv = $_opk;
}

if ( !isset( $return[$var] ) )
{
if ( strpos( $_opv, $arg ) !== false )
{
if ( strpos( $_opv, ':' ) !== false )
{
if ( !isset( $return[$var] ) ) {
if ( strpos( $_opv, $arg ) !== false ) {
if ( strpos( $_opv, ':' ) !== false ) {
if ( isset( $argv[$argPos + 1] )
&& isset( $argv[$argPos + 1][0] )
&& $argv[$argPos + 1][0] != '-')
{
&& $argv[$argPos + 1][0] != '-'
) {
$return[$var] = $argv[++$argPos];
} else {
/*@todo value[1] is a "-" ... missing parameter or is the value ? */
Expand Down Expand Up @@ -305,16 +298,13 @@ public function getCmd()
if ( $k===0 ) {
continue;
}
if ( $v === false || $v === true )
{
foreach ( $this->_options as $opk => $opv )
{
if ( $v === false || $v === true ) {
foreach ( $this->_options as $opk => $opv ) {
if ( is_string( $opk ) ) {
$opv = $opk;
}

if ( preg_match( '/(' . $k . ')/', $opv ) )
{
if ( preg_match( '/(' . $k . ')/', $opv ) ) {
// if ( strpos($opv, ':') )
// {
// if ( $v === false ) {
Expand Down Expand Up @@ -363,8 +353,7 @@ public function getHelp( $wordWrap = 80, $indentComment = " " )
$str = '';
$wrap = $wordWrap - strlen( $indentComment );

foreach ( $this->_options as $k => $v )
{
foreach ( $this->_options as $k => $v ) {
if ( is_string( $k ) ) {
$option = $k;
$desc = $v;
Expand All @@ -387,6 +376,7 @@ public function getHelp( $wordWrap = 80, $indentComment = " " )
$str .= $option . PHP_EOL . $desc;
}
$str = trim( $str );

return $str;
}

Expand All @@ -401,8 +391,7 @@ private function _mapOptions( array $options = array() )
{
$mapping = array();

foreach ( $options as $opkey => $opValue )
{
foreach ( $options as $opkey => $opValue ) {
if ( is_string( $opkey ) ) {
$opValue = $opkey;
}
Expand All @@ -415,8 +404,7 @@ private function _mapOptions( array $options = array() )
// $parts[$pk] = preg_replace('/^(--|-)/', '', $pv, -1);
// }

if ( isset( $parts[1] ) )
{
if ( isset( $parts[1] ) ) {
if ( strlen( $parts[0] ) > strlen( $parts[1] ) ) {
$mapping[$parts[0]] = $parts[0];
$mapping[$parts[1]] = $parts[0];
Expand Down
13 changes: 5 additions & 8 deletions src/Mumsys_Html_Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function setHeadlines( $values = true )
*
* @param array $attr List of key/value pais for the attributes to set
*/
function setHeadlinesAttributes( $attr = array() )
public function setHeadlinesAttributes( $attr = array() )
{
if ( !isset( $this->_headlines['attr']['attr'] ) || !is_array( $this->_headlines['attr']['attr'] ) ) {
$this->_headlines['attr']['attr'] = array();
Expand Down Expand Up @@ -348,8 +348,7 @@ public function setAltRowColor( array $list, $colKey = false )
public function getAltRowColor( $num, $val = null )
{
$return = false;
if ( $this->_altRowColor )
{
if ( $this->_altRowColor ) {
if ( isset( $this->_altRowColorKeyChange ) && $this->_colorChangeVal == $val ) {
$return = current( $this->_altRowColor );
} else {
Expand Down Expand Up @@ -381,8 +380,7 @@ public function getHeadlines()
$values = $this->_headlines['values'];
}

foreach ( $values as $i => $value )
{
foreach ( $values as $i => $value ) {
if ( $this->_headlines['attr'] ) {
$attr = $this->getHeadlinesAttribute( $i ); // sing.
} else {
Expand Down Expand Up @@ -599,7 +597,7 @@ public function toHtml()
{
if ( !$this->_content ) {
throw new Mumsys_Html_Exception( 'No content found to create a table' );
} else {
} else {
$records = $this->_content;
}

Expand Down Expand Up @@ -633,8 +631,7 @@ public function toHtml()

// row begin
$theHtml .= '<tr';
if ( $this->_altRowColor )
{
if ( $this->_altRowColor ) {
if ( isset( $this->_altRowColorKeyChange ) ) {
if ( !isset( $tmp[$this->_altRowColorKeyChange] ) ) {
$message = 'Column key not exists to change a color for rows: "'
Expand Down
34 changes: 12 additions & 22 deletions src/Mumsys_Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,11 +377,10 @@ public function log( $input, $level = 0 )

$levelName = $this->_loglevels[$level];

if ( ( $isArray=is_array( $input ) ) )
{
if ( ( $isArray=is_array( $input ) ) ) {
$_cnt = 0;
$message = '';
foreach( $input as $key => $val ) {
foreach ( $input as $key => $val ) {
//$tmp = 'ff_' . $_cnt . ' key: "' . $key . '", value: "' . $val.'"';
$tmp = 'ff_' . $_cnt . ': array("' . $key . '" => "' . $val . '");';
$message .= sprintf(
Expand All @@ -395,32 +394,26 @@ public function log( $input, $level = 0 )
}

$_cnt++;
}
else
{
} else {
$message = sprintf( $this->_logFormat, $datesting, $this->username, $levelName, $level, $input );
}

$message .= $this->lf;

if ( $level <= $this->logLevel || ( $this->verbose || $this->debug ) )
{
if ( $level <= $this->logLevel || ( $this->verbose || $this->debug ) ) {
if ( $this->_logfile !== false ) {
$this->write( $message );
}
}

if ( $level <= $this->msglogLevel || ( $this->verbose || $this->debug ) )
{
if ( $this->msgEcho )
{
if ( $level <= $this->msglogLevel || ( $this->verbose || $this->debug ) ) {
if ( $this->msgEcho ) {
if ( $this->_logFormatMsg && $this->_logFormatMsg != $this->_logFormat ) {
if ( $isArray )
{
if ( $isArray ) {
$msgOut = '';
$_cnt = 0;
reset( $input );
foreach( $input as $key => $val ) {
foreach ( $input as $key => $val ) {
$tmp = 'ff_' . $_cnt . ': array("' . $key . '" => "' . $val . '");';
$msgOut .= sprintf(
$this->_logFormatMsg,
Expand All @@ -433,9 +426,7 @@ public function log( $input, $level = 0 )
}

$_cnt++;
}
else
{
} else {
$msgOut = sprintf(
$this->_logFormatMsg,
$datesting,
Expand Down Expand Up @@ -518,11 +509,10 @@ public function levelNameGet( $level )
public function checkMaxFilesize()
{
$message = false;
if ( $this->_maxfilesize )
{
if ( $this->_maxfilesize ) {
if ( !( $this->verbose || $this->debug )
&& ( $fsize=@filesize( $this->_logfile ) ) > $this->_maxfilesize)
{
&& ( $fsize=@filesize( $this->_logfile ) ) > $this->_maxfilesize
) {
file_put_contents( $this->_logfile, '' );
$message = 'Max filesize reached. Log purged now';
}
Expand Down
Loading

0 comments on commit 528c2a3

Please sign in to comment.