-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathShortcode.php
More file actions
40 lines (36 loc) · 1.33 KB
/
Copy pathShortcode.php
File metadata and controls
40 lines (36 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
namespace Thunder\Shortcode\Shortcode;
/**
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
*/
final class Shortcode extends AbstractShortcode implements ShortcodeInterface
{
/**
* @param string $name
* @param array $parameters
* @psalm-param array<string,string|null> $parameters
* @param string|null $content
* @param string|null $bbCode
*/
public function __construct($name, array $parameters, $content, $bbCode = null)
{
/** @psalm-suppress RedundantConditionGivenDocblockType, DocblockTypeContradiction */
if(false === is_string($name) || '' === $name) {
throw new \InvalidArgumentException('Shortcode name must be a non-empty string!');
}
foreach($parameters as $value) {
/** @psalm-suppress DocblockTypeContradiction, RedundantConditionGivenDocblockType */
if(false === is_string($value) && null !== $value) {
throw new \InvalidArgumentException('Parameter values must be either string or empty (null)!');
}
}
$this->name = $name;
$this->parameters = $parameters;
$this->content = $content;
$this->bbCode = $bbCode;
}
public function withContent($content)
{
return new self($this->name, $this->parameters, $content, $this->bbCode);
}
}