Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
tools: composer:v2
coverage: none
coverage: pcov
env:
update: true

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
phpunit.xml
.phpunit.cache
.phpunit.result.cache
clover.xml
coverage-report
composer.lock
composer.phar
vendor
Expand Down
4 changes: 4 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
->in(__DIR__)
->exclude([
"local-test",
"docker",
".github",
".vscode",
".phpunit.cache",
"docs",
"vendor",
"node_modules"
]);
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ This package requires **PHP >= 8.2** and supports **Laravel 12 and 13** (via `il

| PHP | Laravel 12 | Laravel 13 |
| --- | :---: | :---: |
| 8.2 | ✅ | — (Laravel 13 requires PHP >= 8.3) |
| 8.2 | ✅ | |
| 8.3 | ✅ | ✅ |
| 8.4 | ✅ | ✅ |
| 8.5 | ✅ | ✅ |
Expand Down
3 changes: 3 additions & 0 deletions docker/php/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ RUN apt-get update \
git \
unzip \
libzip-dev \
$PHPIZE_DEPS \
&& docker-php-ext-install zip \
&& pecl install pcov \
&& docker-php-ext-enable pcov \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
8 changes: 7 additions & 1 deletion src/CloudflareServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ private function setupConfig(): void

if ($this->app instanceof LaravelApplication && $this->app->runningInConsole()) {
$this->publishes([$source => $this->app->configPath('cloudflare.php')]);
} elseif ($this->app instanceof LumenApplication) {
}
// @codeCoverageIgnoreStart
// Lumen is discontinued and not an installed dependency here (only
// referenced for interface compatibility); this branch cannot be
// exercised without adding a dependency on an abandoned framework.
elseif ($this->app instanceof LumenApplication) {
$this->app->configure('cloudflare');
}
// @codeCoverageIgnoreEnd

$this->mergeConfigFrom($source, 'cloudflare');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Configurations/Rules/CacheSettingsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class CacheSettingsRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/ExecuteRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ExecuteRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/LogCustomFieldRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class LogCustomFieldRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/OriginRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class OriginRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/RedirectRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class RedirectRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/RewriteRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class RewriteRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/ScoreRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ScoreRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/ServeErrorRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ class ServeErrorRule extends Rule

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Configurations/Rules/SkipRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function disableLogging(): self

protected function getActionParameters(): ?array
{

return null;
}
}
2 changes: 1 addition & 1 deletion src/Endpoints/Workers/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function create(string $zoneId, array $values): ResponseInterface
{
$this->requiredParams(['pattern'], $values);

return $this->$this->getHttpClient()->post("/zones/{$zoneId}/workers/routes", $values);
return $this->getHttpClient()->post("/zones/{$zoneId}/workers/routes", $values);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Endpoints/Zones/PageRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function create(string $zoneId, array|PageRule $values): ResponseInterfac
$values = $values->toArray();
}

return $this->$this->getHttpClient()->post("/zones/{$zoneId}/pagerules", $values);
return $this->getHttpClient()->post("/zones/{$zoneId}/pagerules", $values);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/MissingArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MissingArgumentException extends \ErrorException
* @param int $code
* @param \Throwable|null $previous
*/
public function __construct($required, int $code = 0, \Throwable $previous = null)
public function __construct($required, int $code = 0, ?\Throwable $previous = null)
{
if (is_string($required)) {
$required = [$required];
Expand Down
4 changes: 4 additions & 0 deletions src/HttpClient/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,17 @@ public function get($target, $key, $default = null)
foreach ($key as $i => $segment) {
unset($key[$i]);

// @codeCoverageIgnoreStart
// $key is always exploded into string segments above, so $segment
// can never actually be null or a float; kept as defensive guards.
if (is_null($segment)) {
return $target;
}

if (is_float($segment)) {
$segment = (string) $segment;
}
// @codeCoverageIgnoreEnd

if (is_array($target) && array_key_exists($segment, $target)) {
$target = $target[$segment];
Expand Down
27 changes: 27 additions & 0 deletions test/Tests/Configurations/Rules/BlockRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\BlockRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class BlockRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new BlockRule(['error' => 'blocked'], 'application/json', 403);

$array = $rule->toArray();

$this->assertSame('block', $array['action']);
$this->assertSame([
'response' => [
'content' => ['error' => 'blocked'],
'content_type' => 'application/json',
'status_code' => 403,
],
], $array['action_parameters']);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/CacheSettingsRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\CacheSettingsRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class CacheSettingsRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new CacheSettingsRule();

$array = $rule->toArray();

$this->assertSame('set_cache_settings', $array['action']);
$this->assertArrayNotHasKey('action_parameters', $array);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/ChallengeRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\ChallengeRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ChallengeRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new ChallengeRule();

$array = $rule->toArray();

$this->assertSame('challenge', $array['action']);
$this->assertArrayNotHasKey('action_parameters', $array);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/CompressionRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\CompressionRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class CompressionRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new CompressionRule('gzip');

$array = $rule->toArray();

$this->assertSame('compress_response', $array['action']);
$this->assertSame(['algorithms' => ['name' => 'gzip']], $array['action_parameters']);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/ConfigRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\ConfigRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ConfigRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new ConfigRule();

$array = $rule->toArray();

$this->assertSame('set_config', $array['action']);
$this->assertSame(['ssl' => 'flexible'], $array['action_parameters']);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/DDoSDynamicRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\DDoSDynamicRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class DDoSDynamicRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new DDoSDynamicRule();

$array = $rule->toArray();

$this->assertSame('ddos_dynamic', $array['action']);
$this->assertArrayNotHasKey('action_parameters', $array);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/ExecuteRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\ExecuteRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ExecuteRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new ExecuteRule();

$array = $rule->toArray();

$this->assertSame('execute', $array['action']);
$this->assertArrayNotHasKey('action_parameters', $array);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/ForceConnectionCloseRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\ForceConnectionCloseRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class ForceConnectionCloseRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new ForceConnectionCloseRule();

$array = $rule->toArray();

$this->assertSame('force_connection_close', $array['action']);
$this->assertArrayNotHasKey('action_parameters', $array);
}
}
21 changes: 21 additions & 0 deletions test/Tests/Configurations/Rules/JSChallengeRuleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Cloudflare\Tests\Configurations\Rules;

use Cloudflare\Configurations\Rules\JSChallengeRule;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;

class JSChallengeRuleTest extends TestCase
{
#[Test]
public function shouldBuildArray()
{
$rule = new JSChallengeRule();

$array = $rule->toArray();

$this->assertSame('js_challenge', $array['action']);
$this->assertArrayNotHasKey('action_parameters', $array);
}
}
Loading
Loading