for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace SimpleSAML\SAML2\XML\mdui;
use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\SAML2\Exception\InvalidArgumentException;
use SimpleSAML\XML\StringElementTrait;
use function filter_var;
/**
* Class implementing DomainHint.
*
* @package simplesamlphp/saml2
*/
final class DomainHint extends AbstractMduiElement
{
use StringElementTrait;
* @param string $content
public function __construct(string $content)
$this->setContent($content);
}
* Sanitize the content of the element.
* @param string $content The unsanitized textContent
* @throws \Exception on failure
* @return string
protected function sanitizeContent(string $content): string
// Remove prefixed schema and/or trailing whitespace + forward slashes
return trimr(preg_replace('#^http[s]?://#i', '', $content), " \n\r\t\v\x00/");
trimr
If this is a false-positive, you can also ignore this issue in your code via the ignore-call annotation
ignore-call
return /** @scrutinizer ignore-call */ trimr(preg_replace('#^http[s]?://#i', '', $content), " \n\r\t\v\x00/");
* Validate the content of the element.
* @param string $content The value to go in the XML textContent
* @return void
protected function validateContent(string $content): void
Assert::notEmpty($content, 'DomainHint cannot be empty');
if (!filter_var($content, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {
throw new InvalidArgumentException(sprintf('DomainHint is not a valid hostname; %s', $content));