Skip to content
Snippets Groups Projects
Unverified Commit eb6e017c authored by Tim van Dijen's avatar Tim van Dijen Committed by GitHub
Browse files

Code quality

parent 9bd7ff61
No related branches found
No related tags found
No related merge requests found
...@@ -7,17 +7,17 @@ ...@@ -7,17 +7,17 @@
* @author Jacob Christiansen, WAYF * @author Jacob Christiansen, WAYF
* @package SimpleSAMLphp * @package SimpleSAMLphp
*/ */
class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_ProcessingFilter { class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_ProcessingFilter
{
/** /**
* Should the pattern found be replaced? * Should the pattern found be replaced?
*/ */
private $replace = FALSE; private $replace = false;
/** /**
* Should the value found be removed? * Should the value found be removed?
*/ */
private $remove = FALSE; private $remove = false;
/** /**
* Pattern to search for. * Pattern to search for.
...@@ -27,7 +27,7 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing ...@@ -27,7 +27,7 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing
/** /**
* String to replace the pattern found with. * String to replace the pattern found with.
*/ */
private $replacement = FALSE; private $replacement = false;
/** /**
* Attribute to search in * Attribute to search in
...@@ -46,7 +46,8 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing ...@@ -46,7 +46,8 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing
* @param mixed $reserved For future use. * @param mixed $reserved For future use.
* @throws SimpleSAML_Error_Exception In case of invalid configuration. * @throws SimpleSAML_Error_Exception In case of invalid configuration.
*/ */
public function __construct($config, $reserved) { public function __construct($config, $reserved)
{
parent::__construct($config, $reserved); parent::__construct($config, $reserved);
assert(is_array($config)); assert(is_array($config));
...@@ -55,33 +56,25 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing ...@@ -55,33 +56,25 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing
foreach ($config as $name => $value) { foreach ($config as $name => $value) {
if (is_int($name)) { if (is_int($name)) {
// check if this is an option // check if this is an option
if($value === '%replace') { if ($value === '%replace') {
$this->replace = TRUE; $this->replace = true;
} elseif ($value === '%remove') { } elseif ($value === '%remove') {
$this->remove = TRUE; $this->remove = true;
} else { } else {
throw new SimpleSAML_Error_Exception('Unknown flag : ' . var_export($value, TRUE)); throw new SimpleSAML_Error_Exception('Unknown flag : ' . var_export($value, true));
} }
continue; continue;
} } elseif ($name === 'pattern') {
// Set pattern
// Set pattern
if ($name === 'pattern') {
$this->pattern = $value; $this->pattern = $value;
} } elseif ($name === 'replacement') {
// Set replacement
// Set replacement
if ($name === 'replacement') {
$this->replacement = $value; $this->replacement = $value;
} } elseif ($name === 'subject') {
// Set subject
// Set subject
if ($name === 'subject') {
$this->subject = $value; $this->subject = $value;
} } elseif ($name === 'target') {
// Set target
// Set target
if ($name === 'target') {
$this->target = $value; $this->target = $value;
} }
} }
...@@ -166,12 +159,19 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing ...@@ -166,12 +159,19 @@ class sspmod_core_Auth_Process_AttributeAlter extends SimpleSAML_Auth_Processing
} }
} else { // replace only the part that matches } else { // replace only the part that matches
if ($this->subject === $this->target) { if ($this->subject === $this->target) {
$attributes[$this->target] = preg_replace($this->pattern, $this->replacement, $attributes[$this->target] = preg_replace(
$attributes[$this->subject]); $this->pattern, $this->replacement,
$attributes[$this->subject]
);
} else { } else {
$attributes[$this->target] = array_diff(preg_replace($this->pattern, $this->replacement, $attributes[$this->target] = array_diff(
$attributes[$this->subject]), preg_replace(
$attributes[$this->subject]); $this->pattern,
$this->replacement,
$attributes[$this->subject]
),
$attributes[$this->subject]
);
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment