Skip to content
Permalink
Browse files

Code formatting

  • Loading branch information
cedx committed May 19, 2020
1 parent 6a155ec commit 2496fa05ad5f47a4eb563cd8fd8e61cd6f9525bd
@@ -3,11 +3,14 @@ root = true

[*]
charset = utf-8
indent_size = 2
indent_style = space
indent_style = tab
insert_final_newline = true
tab_width = 2
trim_trailing_whitespace = true

[*.md]
indent_size = 4
trim_trailing_whitespace = false

[*.{yaml,yml}]
indent_size = 2
indent_style = space
@@ -3,7 +3,7 @@ on:
pull_request:
push:
schedule:
- cron: '0 0 1 * *'
- cron: "0 0 1 * *"
jobs:
test:
runs-on: ubuntu-latest
@@ -1,7 +1,7 @@
{
"editor.insertSpaces": true,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
"editor.insertSpaces": false,
"editor.tabSize": 2,
"files.encoding": "utf8",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true
}
@@ -1,53 +1,53 @@
{
"description": "Prevent comment spam using the Akismet service. Add Akismet to your applications so you don't have to worry about spam again.",
"homepage": "https://docs.belin.io/akismet.php",
"license": "MIT",
"name": "cedx/akismet",
"type": "library",
"version": "12.1.0",
"authors": [
{"email": "cedric@belin.io", "homepage": "https://belin.io", "name": "Cédric Belin"}
],
"autoload": {
"psr-4": {"Akismet\\": "src/"}
},
"autoload-dev": {
"psr-4": {"Akismet\\": "test/"}
},
"config": {
"optimize-autoloader": true
},
"funding": [
{"type": "patreon", "url": "https://www.patreon.com/cedx"}
],
"keywords": [
"akismet",
"comment",
"spam",
"validation"
],
"require": {
"php": ">=7.4.0",
"ext-date": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-pcre": "*",
"nyholm/psr7": "^1.2.1",
"psr/http-client": "^1.0.0",
"symfony/event-dispatcher": "^5.0.8",
"symfony/http-client": "^5.0.8"
},
"require-dev": {
"cedx/coveralls": "^13.0.0",
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^9.1.4"
},
"scripts": {
"coverage": "coveralls var/coverage.xml",
"test": "phpunit --configuration=etc/phpunit.xml"
},
"support": {
"docs": "https://api.belin.io/akismet.php",
"issues": "https://git.belin.io/cedx/akismet.php/issues"
}
"description": "Prevent comment spam using the Akismet service. Add Akismet to your applications so you don't have to worry about spam again.",
"homepage": "https://docs.belin.io/akismet.php",
"license": "MIT",
"name": "cedx/akismet",
"type": "library",
"version": "12.1.0",
"authors": [
{"email": "cedric@belin.io", "homepage": "https://belin.io", "name": "Cédric Belin"}
],
"autoload": {
"psr-4": {"Akismet\\": "src/"}
},
"autoload-dev": {
"psr-4": {"Akismet\\": "test/"}
},
"config": {
"optimize-autoloader": true
},
"funding": [
{"type": "patreon", "url": "https://www.patreon.com/cedx"}
],
"keywords": [
"akismet",
"comment",
"spam",
"validation"
],
"require": {
"php": ">=7.4.0",
"ext-date": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-pcre": "*",
"nyholm/psr7": "^1.2.1",
"psr/http-client": "^1.0.0",
"symfony/event-dispatcher": "^5.0.8",
"symfony/http-client": "^5.0.8"
},
"require-dev": {
"cedx/coveralls": "^13.0.0",
"phpstan/phpstan": "^0.12.25",
"phpunit/phpunit": "^9.1.4"
},
"scripts": {
"coverage": "coveralls var/coverage.xml",
"test": "phpunit --configuration=etc/phpunit.xml"
},
"support": {
"docs": "https://api.belin.io/akismet.php",
"issues": "https://git.belin.io/cedx/akismet.php/issues"
}
}
@@ -9,31 +9,31 @@ The `Akismet\Client` class, used to query the Akismet service, is an [EventDispa
### The `Client::eventRequest` event
Emitted every time a request is made to the remote service:

```php
``` php
<?php
use Akismet\{Blog, Client, RequestEvent};
use Nyholm\Psr7\{Uri};
function main(): void {
$client = new Client('123YourAPIKey', new Blog(new Uri('https://www.yourblog.com')));
$client = new Client("123YourAPIKey", new Blog(new Uri("https://www.yourblog.com")));
$client->addListener(Client::eventRequest, function(RequestEvent $event) {
echo 'Client request: ', $event->getRequest()->getUri();
echo "Client request: ", $event->getRequest()->getUri();
});
}
```

### The `Client::eventResponse` event
Emitted every time a response is received from the remote service:

```php
``` php
<?php
use Akismet\{Blog, Client, ResponseEvent};
use Nyholm\Psr7\{Uri};
function main(): void {
$client = new Client('123YourAPIKey', new Blog(new Uri('https://www.yourblog.com')));
$client = new Client("123YourAPIKey", new Blog(new Uri("https://www.yourblog.com")));
$client->addListener(Client::eventResponse, function(ResponseEvent $event) {
echo 'Server response: ', $event->getResponse()->getStatusCode();
echo "Server response: ", $event->getResponse()->getStatusCode();
});
}
```
@@ -6,20 +6,20 @@ Make a [comment check](../features/comment_check.md) API call with the `Author->

The Akismet API will always return a `CheckResult::isSpam` response to a valid request with one of those values. If you receive anything else, something is wrong in your client, data, or communications.

```php
``` php
<?php
use Akismet\{Author, Blog, Client, Comment};
use Nyholm\Psr7\{Uri};
function main(): void {
$author = (new Author('127.0.0.1', 'Mozilla/5.0'))->setName('viagra-test-123');
$comment = (new Comment($author))->setContent('A user comment');
$author = (new Author("127.0.0.1", "Mozilla/5.0"))->setName("viagra-test-123");
$comment = (new Comment($author))->setContent("A user comment");
$blog = new Blog(new Uri('https://www.yourblog.com'));
$client = new Client('123YourAPIKey', $blog);
$blog = new Blog(new Uri("https://www.yourblog.com"));
$client = new Client("123YourAPIKey", $blog);
$result = $client->checkComment($comment);
echo 'It should be "CheckResult::isSpam": ', $result;
echo "It should be `CheckResult::isSpam`: ", $result;
}
```

@@ -28,20 +28,20 @@ Make a [comment check](../features/comment_check.md) API call with the `Author->

The Akismet API will always return a `CheckResult::isHam` response. Any other response indicates a data or communication problem.

```php
``` php
<?php
use Akismet\{Author, Blog, Client, Comment};
use Nyholm\Psr7\{Uri};
function main(): void {
$author = (new Author('127.0.0.1', 'Mozilla/5.0'))->setRole('administrator');
$comment = (new Comment($author))->setContent('A user comment');
$author = (new Author("127.0.0.1", "Mozilla/5.0"))->setRole("administrator");
$comment = (new Comment($author))->setContent("A user comment");
$blog = new Blog(new Uri('https://www.yourblog.com'));
$client = new Client('123YourAPIKey', $blog);
$blog = new Blog(new Uri("https://www.yourblog.com"));
$client = new Client("123YourAPIKey", $blog);
$result = $client->checkComment($comment);
echo 'It should be "CheckResult::isHam": ', $result;
echo "It should be `CheckResult::isHam`: ", $result;
}
```

@@ -50,19 +50,19 @@ Enable the `Client->isTest()` option in your tests.

That will tell Akismet not to change its behaviour based on those API calls: they will have no training effect. That means your tests will be somewhat repeatable, in the sense that one test won't influence subsequent calls.

```php
``` php
<?php
use Akismet\{Author, Blog, Client, Comment};
use Nyholm\Psr7\{Uri};
function main(): void {
$author = new Author('127.0.0.1', 'Mozilla/5.0');
$comment = (new Comment($author))->setContent('A user comment');
$author = new Author("127.0.0.1", "Mozilla/5.0");
$comment = (new Comment($author))->setContent("A user comment");
$blog = new Blog(new Uri('https://www.yourblog.com'));
$client = (new Client('123YourAPIKey', $blog))->setTest(true);
$blog = new Blog(new Uri("https://www.yourblog.com"));
$client = (new Client("123YourAPIKey", $blog))->setTest(true);
echo 'It should not influence subsequent calls.';
echo "It should not influence subsequent calls.";
$client->checkComment($comment);
}
```
@@ -27,34 +27,34 @@ The `Comment` providing the user message to be checked.
A `CheckResult` value indicating whether the given `Comment` is ham, spam or pervasive spam.

!!! tip
A comment classified as pervasive spam can be safely discarded.
A comment classified as pervasive spam can be safely discarded.

The method throws a `ClientException` when an error occurs.
The exception `getMessage()` usually includes some debug information, provided by the `X-akismet-debug-help` HTTP header, about what exactly was invalid about the call.

## Example

```php
``` php
<?php
use Akismet\{Author, Blog, CheckResult, Client, ClientException, Comment, CommentType};
use Nyholm\Psr7\{Uri};
function main(): void {
try {
$comment = (new Comment(new Author))
->setContent('A user comment')
->setType(CommentType::contactForm);
try {
$comment = (new Comment(new Author))
->setContent("A user comment")
->setType(CommentType::contactForm);
$blog = new Blog(new Uri('https://www.yourblog.com'));
$client = new Client('123YourAPIKey', $blog);
$blog = new Blog(new Uri("https://www.yourblog.com"));
$client = new Client("123YourAPIKey", $blog);
$result = $client->checkComment($comment);
echo $result == CheckResult::isHam ? 'The comment is ham.' : 'The comment is spam.';
}
$result = $client->checkComment($comment);
echo $result == CheckResult::isHam ? "The comment is ham." : "The comment is spam.";
}
catch (ClientException $e) {
echo 'An error occurred: ', $e->getMessage();
}
catch (ClientException $e) {
echo "An error occurred: ", $e->getMessage();
}
}
```

@@ -27,22 +27,22 @@ The exception `getMessage()` usually includes some debug information, provided b

## Example

```php
``` php
<?php
use Akismet\{Blog, Client, ClientException};
use Nyholm\Psr7\{Uri};
function main(): void {
try {
$blog = new Blog(new Uri('https://www.yourblog.com'));
$client = new Client('123YourAPIKey', $blog);
$blog = new Blog(new Uri("https://www.yourblog.com"));
$client = new Client("123YourAPIKey", $blog);
$isValid = $client->verifyKey();
echo $isValid ? 'The API key is valid.' : 'The API key is invalid.';
echo $isValid ? "The API key is valid." : "The API key is invalid.";
}
catch (ClientException $e) {
echo 'An error occurred: ', $e->getMessage();
echo "An error occurred: ", $e->getMessage();
}
}
```
@@ -17,7 +17,7 @@ See the [Akismet API documentation](https://akismet.com/development/api/#submit-
The user `Comment` to be submitted, incorrectly classified as spam.

!!! tip
Ideally, it should be the same object as the one passed to the original [comment check](comment_check.md) API call.
Ideally, it should be the same object as the one passed to the original [comment check](comment_check.md) API call.

## Return value
None.
@@ -27,26 +27,26 @@ The exception `getMessage()` usually includes some debug information, provided b

## Example

```php
``` php
<?php
use Akismet\{Author, Blog, Client, ClientException, Comment};
use Nyholm\Psr7\{Uri};
function main(): void {
try {
$blog = new Blog(new Uri('https://www.yourblog.com'));
$client = new Client('123YourAPIKey', $blog);
try {
$blog = new Blog(new Uri("https://www.yourblog.com"));
$client = new Client("123YourAPIKey", $blog);
$comment = (new Comment(new Author))->setContent('A valid user comment (ham)');
$result = $client->checkComment($comment);
// Got `CheckResult::isSpam`, but `CheckResult::isHam` expected.
$comment = (new Comment(new Author))->setContent("A valid user comment (ham)");
$result = $client->checkComment($comment);
// Got `CheckResult::isSpam`, but `CheckResult::isHam` expected.
echo 'The comment was incorrectly classified as spam.';
$client->submitHam($comment);
}
echo "The comment was incorrectly classified as spam.";
$client->submitHam($comment);
}
catch (ClientException $e) {
echo 'An error occurred: ', $e->getMessage();
}
catch (ClientException $e) {
echo "An error occurred: ", $e->getMessage();
}
}
```

0 comments on commit 2496fa0

Please sign in to comment.