# Contracts Overview

Contracts are interfaces that can be reusable across multiple different libraries and projects. The actual implementation of the interfaces is left up to you.

The interfaces also enhance existing PSRs.

Whenever possible, the components and projects created by Sons of PHP will implement these interfaces.

## Implementation

If you want to provide a concrete library for others to use, add this to your `composer.json` file.

```json
    "provide": {
        "sonsofphp/common-implementation": "^1.0"
    },
```

## Method Naming

Functionality around method names are kept as similar as possible. They SHOULD follow this convention.

### with\*

`with*` methods are meant to be used on value objects. They will return a new object with the value(s) modified.

Examples:

* `withFirstName`

### has\*

Will always return a `boolean` value. Used to check if a property or value exists on the object. Doesn't matter the type of the value.

Examples

* `hasFirstName`

### is\*

Will always return a `boolean` value.

Examples:

* `isNew`
* `isDeleted`

### get\*

Used to return property values.

Examples:

* `getFirstName`
* `getLastName`

### set\*

Used to set property values. SHOULD always return the same instance of the object to allow chaining.

Examples:

* `setFirstName`
* `setLastName`

### to\*

Used to convert an object to a specific format.

Examples:

* `toJson`
* `toString`
* `toArray`
* `toInteger`
* `toFloat`
* `toBoolean`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sonsofphp.com/contracts/index.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
