Skip to content

Commit

Permalink
Automatic coding standard fixes with default php-cs-fixer config (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsw authored Mar 17, 2020
1 parent 1adc8ac commit 791fbcc
Show file tree
Hide file tree
Showing 65 changed files with 959 additions and 1,195 deletions.
598 changes: 194 additions & 404 deletions magmi/engines/magmi_productimportengine.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion magmi/inc/dbhelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ public function rollbackTransaction()
if ($this->_intrans) {
$this->_db->rollBack();
$this->_intrans = false;
// $this->logdebug("-- TRANSACTION ROLLBACK --");
// $this->logdebug("-- TRANSACTION ROLLBACK --");
}
}

Expand Down
47 changes: 26 additions & 21 deletions magmi/inc/magmi_auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,60 @@
*
*/

class Magmi_Auth extends Magmi_Engine {
class Magmi_Auth extends Magmi_Engine
{
private $user;
private $pass;

public function __construct($user,$pass){
public function __construct($user, $pass)
{
parent::__construct();
$this->user = $user;
$this->pass = $pass;
$this->initialize();
try {
$this->connectToMagento();
$this->_hasDB = true;
$this->connectToMagento();
$this->_hasDB = true;
$this->disconnectFromMagento();
}catch (Exception $e){
$this->_hasDB = false;
}

} catch (Exception $e) {
$this->_hasDB = false;
}
}


public function authenticate(){
if (!$this->_hasDB) return ($this->user == 'magmi' && $this->pass == 'magmi');
$tn=$this->tablename('admin_user');
$result = $this->select("SELECT * FROM $tn WHERE username = ?",array($this->user))->fetch(PDO::FETCH_ASSOC);
return $result && $this->validatePass($result['password'],$this->pass);
public function authenticate()
{
if (!$this->_hasDB) {
return ($this->user == 'magmi' && $this->pass == 'magmi');
}
$tn=$this->tablename('admin_user');
$result = $this->select("SELECT * FROM $tn WHERE username = ?", array($this->user))->fetch(PDO::FETCH_ASSOC);
return $result && $this->validatePass($result['password'], $this->pass);
}

private function validatePass($hash,$pass){
private function validatePass($hash, $pass)
{
#first try : standard CE magento hash

$hash = explode(":",$hash);
$hash = explode(":", $hash);
$cecheck = md5($hash[1] . $pass);
$eecheck = hash('sha256',$hash[1] . $pass);
$eecheck = hash('sha256', $hash[1] . $pass);
$eecheckArgo = $this->getArgonHash($pass, $hash[1]);
$valid = ($cecheck == $hash[0] || $eecheck == $hash[0] || $eecheckArgo == $hash[0]);

return $valid;
}
/**
* Generate Argon2ID13 hash.
* Got from \Magento\Framework\Encryption\Encryptor
*
* @param string $data
* @param string $salt
* @return string
*/
private function getArgonHash($data, $salt = ''){
* @return string
*/
private function getArgonHash($data, $salt = '')
{
$salt = empty($salt) ?
random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES) :
substr($salt, 0, SODIUM_CRYPTO_PWHASH_SALTBYTES);
Expand Down
9 changes: 6 additions & 3 deletions magmi/inc/magmi_csvreader.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,10 @@ public function checkCSV()
if (!file_exists($this->_filename)) {
throw new Magmi_CSVException("{$this->_filename} not found");
}
$this->log("Importing CSV : $this->_filename using separator [ $this->_dcsep ] enclosing [ $this->_cenc ]",
"startup");
$this->log(
"Importing CSV : $this->_filename using separator [ $this->_dcsep ] enclosing [ $this->_cenc ]",
"startup"
);
}

public function openCSV()
Expand Down Expand Up @@ -180,7 +182,8 @@ public function getNextRecord()
// if strict matching, warning & continue
$this->log(
"warning: line $this->_curline , wrong column number : $rcols found over $this->_nhcols, line skipped",
"warning");
"warning"
);
continue;
}
break;
Expand Down
3 changes: 2 additions & 1 deletion magmi/inc/magmi_defs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
define("MAGMI_ENGINE_DIR", MAGMI_BASEDIR . '/engines');
set_include_path(
ini_get("include_path") . PATH_SEPARATOR . MAGMI_INCDIR . PATH_SEPARATOR . MAGMI_INTEGRATION_INCDIR . PATH_SEPARATOR .
MAGMI_ENGINE_DIR);
MAGMI_ENGINE_DIR
);
//force UTC date
date_default_timezone_set("UTC");
require_once('magmi_loggers.php');
13 changes: 8 additions & 5 deletions magmi/inc/magmi_engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ public function getPluginInstance($family, $order = -1)
$order += count($this->_activeplugins[$family]);
}

if (is_array($this->_activeplugins) && isset($this->_activeplugins[$family]) && isset($this->_activeplugins[$family][$order]))
if (is_array($this->_activeplugins) && isset($this->_activeplugins[$family]) && isset($this->_activeplugins[$family][$order])) {
return $this->_activeplugins[$family][$order];
}
}

/*
Expand All @@ -289,7 +290,7 @@ public function getPluginInstance($family, $order = -1)
public function callPlugins($types, $callback, &$data = null, $params = null, $break = true)
{
$result = true;
// $tclass=get_class($this);
// $tclass=get_class($this);
// If plugin type list is not an array , process it as string
if (!is_array($types)) {
// If plugin is not wildcard , build array of types based on comma separated string
Expand All @@ -301,7 +302,7 @@ public function callPlugins($types, $callback, &$data = null, $params = null, $b
}

// Timing initialization (global processing step)
// $this->_timecounter->initTime($callback, get_class($this));
// $this->_timecounter->initTime($callback, get_class($this));

// Iterate on plugin types (families)
foreach ($types as $ptype) {
Expand All @@ -318,7 +319,9 @@ public function callPlugins($types, $callback, &$data = null, $params = null, $b
// either with or without parameters,or parameters & data
// store execution result
$callres = ($data == null ? ($params == null ? $pinst->$callback() : $pinst->$callback($params)) : $pinst->$callback(
$data, $params));
$data,
$params
));
// End Timing for current plugin in current step
//$this->_timecounter->exitTime($callback, get_class($pinst));
// if plugin call result is false with data set
Expand All @@ -332,7 +335,7 @@ public function callPlugins($types, $callback, &$data = null, $params = null, $b
// Call the plugin processing loop callback , time it
//$this->_timecounter->initTime($callback, $pclass);
$this->$cb($pinst, $data, $result);
// $this->_timecounter->exitTime($callback, $pclass);
// $this->_timecounter->exitTime($callback, $pclass);
}
// if last result plugin is false & break flag
if ($result === false && $break) {
Expand Down
9 changes: 6 additions & 3 deletions magmi/inc/magmi_pluginhelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public function __construct($profile = null)
$this->plugin_dir = realpath(dirname(dirname(__FILE__)) . DIRSEP . "plugins");
// set include path to inclue plugins inc & base dir
set_include_path(
ini_get("include_path") . PATH_SEPARATOR . "$this->plugin_dir/inc" . PATH_SEPARATOR . "$this->base_dir");
ini_get("include_path") . PATH_SEPARATOR . "$this->plugin_dir/inc" . PATH_SEPARATOR . "$this->base_dir"
);
// add base classes in context
require_once("magmi_item_processor.php");
require_once("magmi_datasource.php");
Expand Down Expand Up @@ -97,8 +98,10 @@ public function scanPlugins($pltypes)
}
foreach ($pltypes as $pltype) {
if (!isset(self::$_plugins_cache[$pltype])) {
self::$_plugins_cache[$pltype] = self::initPluginInfos($this->_plmeta[$pltype][0],
$this->_plmeta[$pltype][1]);
self::$_plugins_cache[$pltype] = self::initPluginInfos(
$this->_plmeta[$pltype][0],
$this->_plmeta[$pltype][1]
);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion magmi/inc/magmi_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function truepath($path)
if (strpos($path, ':') === false && $unipath) {
$path = getcwd() . DIRECTORY_SEPARATOR . $path;
}
// resolve path parts (single dot, double dot and double delimiters)
// resolve path parts (single dot, double dot and double delimiters)
$path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path);
$parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen');
$absolutes = array();
Expand Down
27 changes: 10 additions & 17 deletions magmi/inc/magmi_valueparser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,26 @@

class Magmi_ValueParser
{

public static function getParseInfo($pvalue,$dictarray)
public static function getParseInfo($pvalue, $dictarray)
{
$parseinfo=array();

foreach ($dictarray as $key=>$v)
{
if(preg_match("|\{\{\s*(.*?)\s*\}\}|s", $pvalue,$matches))
{
if(!isset($parseinfo["complex"])){
foreach ($dictarray as $key=>$v) {
if (preg_match("|\{\{\s*(.*?)\s*\}\}|s", $pvalue, $matches)) {
if (!isset($parseinfo["complex"])) {
$parseinfo["complex"]=array();
}
for($i=1;$i<count($matches);$i++)
{
for ($i=1;$i<count($matches);$i++) {
$parseinfo["complex"][]=$matches[$i];
}
}

if(preg_match("|\{$key\.(.*?)\}|", $pvalue,$matches))
{
if(!isset($parseinfo["simple"]))
{
if (preg_match("|\{$key\.(.*?)\}|", $pvalue, $matches)) {
if (!isset($parseinfo["simple"])) {
$parseinfo["simple"] = array("$key"=>array());
}

for($i=1;$i<count($matches);$i++)
{
for ($i=1;$i<count($matches);$i++) {
$parseinfo["simple"][$key]=$matches[$i];
}
}
Expand Down Expand Up @@ -72,8 +65,8 @@ public static function parseValue($pvalue, $dictarray)
if ($match != $matches[0]) {
$code = trim($match);
$code = str_replace($renc, '"', $code);
$code = str_replace("'\"","'",$code);
$code = str_replace("\"'","'",$code);
$code = str_replace("'\"", "'", $code);
$code = str_replace("\"'", "'", $code);

$rep = eval("return ($code);");
// escape potential "{{xxx}}" values in interpreted target
Expand Down
8 changes: 4 additions & 4 deletions magmi/inc/magmi_version.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
class Magmi_Version
{
public static $version="0.7.23-git";
}
class Magmi_Version
{
public static $version="0.7.23-git";
}
Loading

0 comments on commit 791fbcc

Please sign in to comment.