Skip to content

Commit 884dd95

Browse files
committed
full Psalm type coverage
1 parent 79a219f commit 884dd95

39 files changed

+649
-85
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.phpunit.result.cache
12
vendor
23
composer.lock
34
coverage

.travis.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ php:
1010
- 7.1
1111
- 7.2
1212
- 7.3
13-
- 7.4snapshot
13+
- 7.4
1414
- hhvm
1515
- nightly
1616

@@ -21,6 +21,10 @@ before_script:
2121

2222
script:
2323
- vendor/bin/phpunit --coverage-text
24+
- |
25+
if php -r 'exit((int)(version_compare(PHP_VERSION, "7.1", ">=") === false));';
26+
then composer require --dev vimeo/psalm && vendor/bin/psalm --threads=8 --no-cache --shepherd --find-unused-psalm-suppress;
27+
fi;
2428
2529
after_script:
2630
- wget https://scrutinizer-ci.com/ocular.phar
@@ -31,4 +35,3 @@ matrix:
3135
- php: 5.3
3236
- php: hhvm
3337
- php: nightly
34-
- php: hhvm

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Shortcode
22

3-
[![Build Status](https://travis-ci.org/thunderer/Shortcode.png?branch=master)](https://travis-ci.org/thunderer/Shortcode)
3+
[![Build Status](https://travis-ci.com/thunderer/Shortcode.svg?branch=master)](https://travis-ci.com/thunderer/Shortcode)
44
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/5235d5e3-d112-48df-bc07-d4555aef293d/mini.png)](https://insight.sensiolabs.com/projects/5235d5e3-d112-48df-bc07-d4555aef293d)
55
[![License](https://poser.pugx.org/thunderer/shortcode/license.svg)](https://packagist.org/packages/thunderer/shortcode)
66
[![Latest Stable Version](https://poser.pugx.org/thunderer/shortcode/v/stable.svg)](https://packagist.org/packages/thunderer/shortcode)
77
[![Total Downloads](https://poser.pugx.org/thunderer/shortcode/downloads)](https://packagist.org/packages/thunderer/shortcode)
8-
[![Dependency Status](https://www.versioneye.com/user/projects/551d5385971f7847ca000002/badge.svg)](https://www.versioneye.com/user/projects/551d5385971f7847ca000002)
8+
[![Psalm coverage](https://shepherd.dev/github/thunderer/Shortcode/coverage.svg?)](https://shepherd.dev/github/thunderer/Shortcode)
99
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/thunderer/Shortcode/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/thunderer/Shortcode/?branch=master)
1010
[![Code Coverage](https://scrutinizer-ci.com/g/thunderer/Shortcode/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/thunderer/Shortcode/?branch=master)
1111
[![Code Climate](https://codeclimate.com/github/thunderer/Shortcode/badges/gpa.svg)](https://codeclimate.com/github/thunderer/Shortcode)
@@ -33,18 +33,18 @@ Each part is described in the dedicated section in this document.
3333

3434
## Installation
3535

36-
There are no required dependencies and all PHP versions from 5.3 up to latest 7.0 [are tested](https://travis-ci.org/thunderer/Shortcode) and supported. This library is available on Composer/Packagist as `thunderer/shortcode`, to install it execute:
36+
There are no required dependencies and all PHP versions from 5.3 up to latest 7.4 [are tested](https://travis-ci.org/thunderer/Shortcode) and supported. This library is available on Composer/Packagist as `thunderer/shortcode`, to install it execute:
3737

3838
```
39-
composer require thunderer/shortcode=^0.7.3
39+
composer require thunderer/shortcode=^0.7
4040
```
4141

4242
or manually update your `composer.json` with:
4343

4444
```
4545
(...)
4646
"require": {
47-
"thunderer/shortcode": "^0.7.3"
47+
"thunderer/shortcode": "^0.7"
4848
}
4949
(...)
5050
```

psalm.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
totallyTyped="true"
4+
findUnusedCode="false"
5+
findUnusedVariablesAndParams="true"
6+
findUnusedPsalmSuppress="true"
7+
resolveFromConfigFile="true"
8+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xmlns="https://getpsalm.org/schema/config"
10+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd">
11+
12+
<projectFiles>
13+
<directory name="src" />
14+
<ignoreFiles>
15+
<directory name="vendor" />
16+
</ignoreFiles>
17+
</projectFiles>
18+
19+
</psalm>

src/Event/FilterShortcodesEvent.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,35 @@
1313
*/
1414
class FilterShortcodesEvent
1515
{
16+
/** @var ProcessedShortcode|null */
1617
private $parent;
17-
private $shortcodes;
18+
/** @var ParsedShortcodeInterface[] */
19+
private $shortcodes = array();
1820

21+
/** @param ParsedShortcodeInterface[] $shortcodes */
1922
public function __construct(array $shortcodes, ProcessedShortcode $parent = null)
2023
{
2124
$this->parent = $parent;
2225
$this->setShortcodes($shortcodes);
2326
}
2427

25-
/**
26-
* @return ParsedShortcodeInterface[]
27-
*/
28+
/** @return ParsedShortcodeInterface[] */
2829
public function getShortcodes()
2930
{
3031
return $this->shortcodes;
3132
}
3233

34+
/** @return ProcessedShortcode|null */
3335
public function getParent()
3436
{
3537
return $this->parent;
3638
}
3739

40+
/**
41+
* @param ParsedShortcodeInterface[] $shortcodes
42+
*
43+
* @return void
44+
*/
3845
public function setShortcodes(array $shortcodes)
3946
{
4047
$this->shortcodes = array();
@@ -43,6 +50,11 @@ public function setShortcodes(array $shortcodes)
4350
}
4451
}
4552

53+
/**
54+
* @param ParsedShortcodeInterface $shortcode
55+
*
56+
* @return void
57+
*/
4658
private function addShortcode(ParsedShortcodeInterface $shortcode)
4759
{
4860
$this->shortcodes[] = $shortcode;

src/Event/ReplaceShortcodesEvent.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@
1313
*/
1414
class ReplaceShortcodesEvent
1515
{
16+
/** @var ShortcodeInterface|null */
1617
private $shortcode;
18+
/** @var string */
1719
private $text;
1820
/** @var ReplacedShortcode[] */
19-
private $replacements;
21+
private $replacements = array();
22+
/** @var string|null */
2023
private $result;
2124

25+
/**
26+
* @param string $text
27+
* @param ReplacedShortcode[] $replacements
28+
*/
2229
public function __construct($text, array $replacements, ShortcodeInterface $shortcode = null)
2330
{
2431
$this->shortcode = $shortcode;
@@ -27,43 +34,59 @@ public function __construct($text, array $replacements, ShortcodeInterface $shor
2734
$this->setReplacements($replacements);
2835
}
2936

37+
/**
38+
* @param ReplacedShortcode[] $replacements
39+
*
40+
* @return void
41+
*/
3042
private function setReplacements(array $replacements)
3143
{
3244
foreach($replacements as $replacement) {
3345
$this->addReplacement($replacement);
3446
}
3547
}
3648

49+
/** @return void */
3750
private function addReplacement(ReplacedShortcode $replacement)
3851
{
3952
$this->replacements[] = $replacement;
4053
}
4154

55+
/** @return string */
4256
public function getText()
4357
{
4458
return $this->text;
4559
}
4660

61+
/** @return ReplacedShortcode[] */
4762
public function getReplacements()
4863
{
4964
return $this->replacements;
5065
}
5166

67+
/** @return ShortcodeInterface|null */
5268
public function getShortcode()
5369
{
5470
return $this->shortcode;
5571
}
5672

73+
/**
74+
* @param string $result
75+
*
76+
* @return void
77+
*/
5778
public function setResult($result)
5879
{
5980
$this->result = $result;
6081
}
6182

83+
/** @return string|null */
6284
public function getResult()
6385
{
6486
return $this->result;
6587
}
6688

89+
/** @return bool */
6790
public function hasResult()
6891
{
6992
return null !== $this->result;

src/EventContainer/EventContainer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@
88
*/
99
final class EventContainer implements EventContainerInterface
1010
{
11+
/** @psalm-var array<string,list<callable>> */
1112
private $listeners = array();
1213

1314
public function __construct()
1415
{
1516
}
1617

18+
/**
19+
* @param string $event
20+
* @param callable $handler
21+
*
22+
* @return void
23+
*/
1724
public function addListener($event, $handler)
1825
{
1926
if(!\in_array($event, Events::getEvents(), true)) {
@@ -27,11 +34,21 @@ public function addListener($event, $handler)
2734
$this->listeners[$event][] = $handler;
2835
}
2936

37+
/**
38+
* @param string $event
39+
*
40+
* @psalm-return list<callable>
41+
*/
3042
public function getListeners($event)
3143
{
3244
return $this->hasEvent($event) ? $this->listeners[$event] : array();
3345
}
3446

47+
/**
48+
* @param string $name
49+
*
50+
* @return bool
51+
*/
3552
private function hasEvent($name)
3653
{
3754
return array_key_exists($name, $this->listeners);

src/EventHandler/ReplaceJoinEventHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public function __construct(array $names)
2424

2525
public function __invoke(ReplaceShortcodesEvent $event)
2626
{
27-
if($event->getShortcode() && in_array($event->getShortcode()->getName(), $this->names)) {
27+
$shortcode = $event->getShortcode();
28+
if($shortcode && in_array($shortcode->getName(), $this->names)) {
2829
$replaces = array();
2930
foreach($event->getReplacements() as $r) {
3031
$replaces[] = $r->getReplacement();

src/Events.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ final class Events
99
const FILTER_SHORTCODES = 'event.filter-shortcodes';
1010
const REPLACE_SHORTCODES = 'event.replace-shortcodes';
1111

12+
/** @return string[] */
1213
public static function getEvents()
1314
{
1415
return array(static::FILTER_SHORTCODES, static::REPLACE_SHORTCODES);

src/Handler/DeclareHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ final class DeclareHandler
1111
{
1212
/** @var HandlerContainer */
1313
private $handlers;
14+
/** @var string */
1415
private $delimiter;
1516

17+
/** @param string $delimiter */
1618
public function __construct(HandlerContainer $container, $delimiter = '%')
1719
{
1820
$this->handlers = $container;
@@ -33,12 +35,13 @@ public function __invoke(ShortcodeInterface $shortcode)
3335
}
3436
$keys = array_keys($args);
3537
$name = array_shift($keys);
36-
$content = $shortcode->getContent();
38+
$content = (string)$shortcode->getContent();
3739
$delimiter = $this->delimiter;
3840

3941
$this->handlers->add($name, function(ShortcodeInterface $shortcode) use($content, $delimiter) {
4042
$args = $shortcode->getParameters();
4143
$keys = array_map(function($key) use($delimiter) { return $delimiter.$key.$delimiter; }, array_keys($args));
44+
/** @var string[] $values */
4245
$values = array_values($args);
4346

4447
return str_replace($keys, $values, $content);

0 commit comments

Comments
 (0)