⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions src/internals/014-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,40 @@ containing the translations. The following shows an example for German:
}
```

## PHPDoc
## Code comments and PHPDoc

PHPDoc mustn't be added if it doesn't add anything to what it describes. The following is a bad example:
PHPDoc should not be added if it doesn't provide any additional value.
In the example below, comments add real value by explaining what the code does and why:

```php
<?php

declare(strict_types=1);

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class WebhookController
{
public function payment(ServerRequestInterface $request): ResponseInterface
{
// Verify webhook signature
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for feedback. I will search for another example.

$signature = $request->getHeaderLine('X-Webhook-Signature');
$payload = (string) $request->getBody();
$expectedSignature = hash_hmac('sha256', $payload, $this->webhookSecret);

if (!hash_equals($signature, $expectedSignature)) {
throw new \RuntimeException('Invalid webhook signature');
}

// Process webhook payload
// ...
}
}
```

PHPDoc, if present, should describe the purpose of the element it's added for.
The following is a bad example:

```php
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -120,9 +151,7 @@ final class MyService extends MyServiceBase
return parent::doit();
}
}
```

PHPDoc, if present, should describe the purpose of the element it's added for.
```

## Readme checklist

Expand Down