Skip to content

Commit

Permalink
Merge pull request #9 from szepeviktor/ci/3-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath authored Jun 7, 2020
2 parents 660a101 + 75b16f9 commit 42101e8
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/composer.json export-ignore
/composer.lock export-ignore
/contributing.md export-ignore
/phpstan.neon.dist export-ignore

# Handle line endings.
# See https://help.github.com/articles/dealing-with-line-endings/
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
composer.lock
/vendor
/composer.lock
/vendor/
16 changes: 16 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,21 @@
},
"require" : {
"php" : ">=5.6"
},
"require-dev": {
"php" : "~7.1",
"wp-coding-standards/wpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2",
"szepeviktor/phpstan-wordpress": "^0.6.0"
},
"scripts": {
"ci:syntax": "find src/ -type f -name '*.php' -print0|xargs -0 -L 1 -- php -l",
"ci:coding-standars": "phpcs --standard=WordPress-Core --exclude=Generic.Arrays.DisallowShortArraySyntax src/",
"ci:static-analysis": "phpstan analyze",
"test": [
"@ci:syntax",
"@ci:coding-standars",
"@ci:static-analysis"
]
}
}
9 changes: 9 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
includes:
- vendor/szepeviktor/phpstan-wordpress/extension.neon
parameters:
level: max
inferPrivatePropertyTypeFromConstructor: true
# TODO Add array types
checkMissingIterableValueType: false
paths:
- src/
1 change: 1 addition & 0 deletions src/Dismiss.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Dismiss {
* @since 1.0
* @param string $id A unique ID for this notice. Can contain lowercase characters and underscores.
* @param string $prefix The prefix that will be used for the option/user-meta.
* @param string $scope Controls where the dismissal will be saved: user or global.
*/
public function __construct( $id, $prefix, $scope = 'global' ) {

Expand Down
20 changes: 11 additions & 9 deletions src/Notice.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ class Notice {
private $allowed_html = [
'p' => [],
'a' => [
'href' => [],
'rel' => [],
'href' => [],
'rel' => [],
],
'em' => [],
'strong' => [],
Expand All @@ -103,7 +103,7 @@ class Notice {
'info',
'success',
'error',
'warning'
'warning',
];

/**
Expand Down Expand Up @@ -135,10 +135,10 @@ class Notice {
public function __construct( $id, $title, $message, $options = [] ) {

// Set the object properties.
$this->id = $id;
$this->title = $title;
$this->message = $message;
$this->options = wp_parse_args( $options, $this->options );
$this->id = $id;
$this->title = $title;
$this->message = $message;
$this->options = wp_parse_args( $options, $this->options );

// Sanity check: Early exit if ID or message are empty.
if ( ! $this->id || ! $this->message ) {
Expand Down Expand Up @@ -225,7 +225,7 @@ public function get_classes() {
];

// Make sure the defined type is allowed.
$this->options['type'] = in_array( $this->options['type'], $this->allowed_types ) ? $this->options['type'] : 'info';
$this->options['type'] = in_array( $this->options['type'], $this->allowed_types, true ) ? $this->options['type'] : 'info';

// Add the class for notice-type.
$classes[] = 'notice-' . $this->options['type'];
Expand Down Expand Up @@ -289,7 +289,9 @@ private function is_screen() {
require_once ABSPATH . 'wp-admin/includes/screen.php';
}

/** @var \WP_Screen $current_screen */
$current_screen = get_current_screen();
// Check if we're on one of the defined screens.
return ( in_array( get_current_screen()->id, $this->options['screens'], true ) );
return ( in_array( $current_screen->id, $this->options['screens'], true ) );
}
}

0 comments on commit 42101e8

Please sign in to comment.