Skip to content

Commit

Permalink
Add attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Oct 30, 2020
1 parent 1a44670 commit 3831f0d
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 0 deletions.
40 changes: 40 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "psalm/attributes",
"type": "library",
"description": "A collection of PHP 8 Attributes that Psalm can understand",
"keywords": [
"php",
"attributes",
"static analysis"
],
"license": "MIT",
"authors": [
{
"name": "Matthew Brown"
}
],
"require": {
"php": ">=8"
},
"require-dev": {
"vimeo/psalm": "dev-master"
},
"autoload": {
"psr-4": {
"Psalm\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Psalm\\Tests\\": "tests/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"all-tests": [
"./psalm"
],
"psalm": "./psalm"
}
}
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
8 changes: 8 additions & 0 deletions src/BaseAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
namespace Psalm;

/**
* Exists just in case someone wants to grab all Psalm attributes during reflection
*/
abstract class BaseAttribute
{}
15 changes: 15 additions & 0 deletions src/Deprecated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Psalm;

use Attribute;

#[Attribute]
#[Immutable]
final class Deprecated extends BaseAttribute
{
public function __construct(
public ?string $since_version = null,
public ?string $reason = null,
public ?string $replacement = null,
) {}
}
9 changes: 9 additions & 0 deletions src/ExternalMutationFree.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Psalm;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
#[Immutable]
final class ExternalMutationFree extends BaseAttribute
{}
9 changes: 9 additions & 0 deletions src/Immutable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Psalm;

use Attribute;

#[Attribute(Attribute::TARGET_CLASS)]
#[Immutable]
final class Immutable extends BaseAttribute
{}
9 changes: 9 additions & 0 deletions src/Internal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Psalm;

use Attribute;

#[Attribute]
#[Immutable]
final class Internal extends BaseAttribute
{}
9 changes: 9 additions & 0 deletions src/Pure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Psalm;

use Attribute;

#[Attribute(Attribute::TARGET_FUNCTION | Attribute::TARGET_METHOD)]
#[Immutable]
final class Pure extends BaseAttribute
{}
9 changes: 9 additions & 0 deletions src/Readonly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Psalm;

use Attribute;

#[Attribute(Attribute::TARGET_PROPERTY)]
#[Immutable]
final class Readonly extends BaseAttribute
{}

0 comments on commit 3831f0d

Please sign in to comment.