> For the complete documentation index, see [llms.txt](https://anton-d-perera.gitbook.io/php-attributes-reader/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anton-d-perera.gitbook.io/php-attributes-reader/reading-attributes/method-attributes.md).

# Method Attributes

PHP Class with Class Attributes

```php
<?php

declare(strict_types=1);

class Abc
{
    #[TestAttribute11(["key1" => "key1 value"])]
    #[TestAttribute12(10.13)]
    #[TestAttribute13(123)]
    #[TestAttribute14()]
    #[TestAttribute15(["value1", "value2"])]
    public function function1() {
        // rest of the codes
    }
    // rest of the codes
}
```

\
Initialize the Attributes Reader

```php
<?php

declare(strict_types=1);

use \AntonDPerera\PHPAttributesReader\AttributesReader;

$class = Abc::class;

$attributes_reader = AttributesReader($class);
```

### Available functions for Method Attributes

```php
public function hasMethodAttributes(?string $method_name = null): bool
```

1. If `$method_name` is `null`, returns `true` or `false` based on availability of Method attributes in the class.
2. If `$method_name` is not `null`, returns `true` or `false` based on availability of Method attributes for the given `$method_name`.

```php
public function getMethodAttributes(?string $method_name = null): array | MethodNotFoundException
```

1. If `$method_name` is `null`, returns all the Method attributes in the class.
2. If $method\_name is not `null`, returns all the Method attributes for the given method name.\
   It will be an array of attributes. Each item on Array will be an instance of Attribute class

   ```php
   \AntonDPerera\PHPAttributesReader\Attribute
   ```

   Refer [Attribute class Reference documentation](/php-attributes-reader/reading-attributes/attribute-class.md) for more details.
3. If given `$method_name` is not available within the list of Method attributes, this function will throws `AntonDPerera\PHPAttributesReader\Exceptions\MethodNotFoundException`.

```php
public function getMethodAttribute(string $method_name, string $attribute_name): Attribute | MethodAttributeNotFoundException
```

1. If given `$method_name` is not available within the list of Method attributes, this function will throws `AntonDPerera\PHPAttributesReader\Exceptions\MethodNotFoundException`.
2. If given `$method_name` is available within the list of Method attributes but the given `$attribute_name` doesn't exists in the attributes list this function will throws `AntonDPerera\PHPAttributesReader\Exceptions\MethodAttributeNotFoundException`.
3. If given `$method_name` is available within the list of Method attributes and the given `$attribute_name` exists too for that method, this function will return an instance of Attribute class.\
   Refer [Attribute class Reference documentation](/php-attributes-reader/reading-attributes/attribute-class.md) for more details.
