diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..2004851 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,10 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + +jobs: + ci: + uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 455a58f..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: php - -dist: trusty - -env: - global: - - COMPOSER_ROOT_VERSION=4.0.x-dev - -matrix: - include: - - php: 7.1 - env: - - DB=MYSQL - - PHPUNIT_COVERAGE_TEST=1 - - RECIPE_VERSION=4.2.x-dev - - php: 7.2 - env: - - DB=MYSQL - - PHPUNIT_COVERAGE_TEST=1 - - RECIPE_VERSION=4.2.x-dev - - php: 7.3 - env: - - DB=MYSQL - - PHPUNIT_COVERAGE_TEST=1 - - RECIPE_VERSION=4.x-dev - -before_script: - # Init PHP - - phpenv rehash - - phpenv config-rm xdebug.ini - - # Install composer dependencies - - composer validate - - composer require --no-update silverstripe/recipe-cms:"$RECIPE_VERSION" - - composer install --prefer-dist --no-interaction --no-progress --no-suggest --optimize-autoloader --verbose --profile - -script: - - if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/php; fi - - if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml tests/php; fi - -after_success: - - if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi diff --git a/composer.json b/composer.json index a302094..3c487c6 100644 --- a/composer.json +++ b/composer.json @@ -23,15 +23,15 @@ "issues": "http://github.com/ichaber/silverstripe-swiftype/issues" }, "require": { - "php": "^7.1", - "silverstripe/vendor-plugin": "^1", + "php": "^7.4 || ^8.0", + "silverstripe/vendor-plugin": "^1.6", "silverstripe/framework": "^4", "silverstripe/cms": "^4", - "guzzlehttp/guzzle": "^6.3.0", - "guzzlehttp/psr7": "^1.4.2" + "guzzlehttp/guzzle": "^7", + "guzzlehttp/psr7": "^2" }, "require-dev": { - "phpunit/phpunit": "^5.7" + "silverstripe/recipe-testing": "^2" }, "autoload": { "psr-4": { @@ -43,5 +43,12 @@ "installer-name": "silverstripe-swiftype" }, "prefer-stable": true, - "minimum-stability": "dev" + "minimum-stability": "dev", + "config": { + "allow-plugins": { + "composer/installers": true, + "silverstripe/recipe-plugin": true, + "silverstripe/vendor-plugin": true + } + } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..5779613 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,26 @@ + + + CodeSniffer ruleset for SilverStripe coding conventions. + + src + tests + + + + + + + + + + + + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 965f16a..2fdf2b1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,17 @@ - - - tests/php/ - - - + + + + src/ - - tests/ - - - + + + tests/ + + + + + tests/ + + diff --git a/src/Extensions/SwiftypeMetaTagContentExtension.php b/src/Extensions/SwiftypeMetaTagContentExtension.php index ccab3df..2aab54e 100644 --- a/src/Extensions/SwiftypeMetaTagContentExtension.php +++ b/src/Extensions/SwiftypeMetaTagContentExtension.php @@ -9,9 +9,6 @@ use SilverStripe\ORM\FieldType\DBField; /** - * Class SwiftypeMetaTagContentExtension - * - * @package Ichaber\SSSwiftype\Extensions * @property DataObject|$this $owner */ class SwiftypeMetaTagContentExtension extends DataExtension diff --git a/src/Extensions/SwiftypeSiteConfigFieldsExtension.php b/src/Extensions/SwiftypeSiteConfigFieldsExtension.php index c0788fb..f655041 100644 --- a/src/Extensions/SwiftypeSiteConfigFieldsExtension.php +++ b/src/Extensions/SwiftypeSiteConfigFieldsExtension.php @@ -11,9 +11,6 @@ /** * Some default things to set up * - * Class SwiftypeSiteConfigFieldsExtension - * - * @package Ichaber\SSSwiftype\Extensions * @property bool $SwiftypeEnabled * @property string $SwiftypeAccessKey * @property string $SwiftypeAPIKey @@ -39,8 +36,6 @@ class SwiftypeSiteConfigFieldsExtension extends DataExtension * Settings and CMS form fields for CMS the admin/settings area * * @codeCoverageIgnore - * @param FieldList $fields - * @return void */ public function updateCMSFields(FieldList $fields): void { diff --git a/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php b/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php index 239ce5f..222b1c0 100644 --- a/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php +++ b/src/Extensions/SwiftypeSiteTreeCrawlerExtension.php @@ -10,9 +10,6 @@ use SilverStripe\Versioned\Versioned; /** - * Class SwiftypeSiteTreeCrawlerExtension - * - * @package Ichaber\SSSwiftype\Extensions * @property SiteTree|$this $owner */ class SwiftypeSiteTreeCrawlerExtension extends SiteTreeExtension @@ -26,16 +23,11 @@ class SwiftypeSiteTreeCrawlerExtension extends SiteTreeExtension */ private $urlsToCrawl = []; - /** - * @param array $urls - */ - public function setUrlsToCrawl(array $urls) { + public function setUrlsToCrawl(array $urls) + { $this->urlsToCrawl = $urls; } - /** - * @return array - */ public function getUrlsToCrawl(): array { return $this->urlsToCrawl; @@ -56,7 +48,6 @@ public function onBeforeWrite(): void * an unpublish) * * @param SiteTree|mixed $original - * @return void */ public function onAfterPublish(&$original): void { @@ -162,7 +153,7 @@ public function collateUrls(): void $urls = $this->getUrlsToCrawl(); // Set us to a LIVE stage/reading_mode - $this->withVersionContext(function() use (&$urls) { + $this->withVersionContext(function () use (&$urls) { /** @var SiteTree $owner */ $owner = $this->getOwner(); $key = $this->getOwnerKey(); @@ -225,15 +216,11 @@ protected function processCollatedUrls(): void } // Force the reindexing of each URL we collated - foreach ($urls[$key] as $url) { + foreach ($urls[$key] as $url) { $this->forceSwiftypeIndex($url); } } - /** - * @param string $updateUrl - * @return bool - */ protected function forceSwiftypeIndex(string $updateUrl): bool { // We don't reindex dev environments @@ -246,9 +233,6 @@ protected function forceSwiftypeIndex(string $updateUrl): bool return $crawler->send($updateUrl); } - /** - * @return string - */ protected function getOwnerKey(): ?string { $owner = $this->owner; @@ -269,12 +253,10 @@ protected function getOwnerKey(): ?string * The main function is to suppress the ?stage=Live querystring. LeftAndMain will set the default * reading mode to 'DRAFT' when initialising so to counter this we need to re-set the default * reading mode back to LIVE - * - * @param callable $callback */ private function withVersionContext(callable $callback): void { - Versioned::withVersionedMode(static function() use ($callback) { + Versioned::withVersionedMode(static function () use ($callback) { // Grab our current stage and reading mode $originalDefaultReadingMode = Versioned::get_default_reading_mode(); $originalReadingMode = Versioned::get_reading_mode(); diff --git a/src/MetaTags/SwiftypeMetaTag.php b/src/MetaTags/SwiftypeMetaTag.php index 2df7fe9..ff1a250 100644 --- a/src/MetaTags/SwiftypeMetaTag.php +++ b/src/MetaTags/SwiftypeMetaTag.php @@ -8,9 +8,6 @@ use SilverStripe\ORM\FieldType\DBDatetime; /** - * Class SwiftypeMetaTag - * - * @package Ichaber\SSSwiftype\MetaTags * @see _config/model.yml for DateFormat definition * @see _config/model.yml for field_name override example */ @@ -33,10 +30,6 @@ abstract class SwiftypeMetaTag implements SwiftypeMetaTagInterface */ protected $fieldType; - /** - * @param DataObject $dataObject - * @return null|string - */ public function getMetaTagString(DataObject $dataObject): ?string { // Can't do anything if no tag name was specified @@ -61,7 +54,6 @@ public function getMetaTagString(DataObject $dataObject): ?string } /** - * @param DataObject $dataObject * @return string|int|null */ protected function getFieldValue(DataObject $dataObject) @@ -111,12 +103,6 @@ protected function getFieldValue(DataObject $dataObject) return null; } - /** - * @param string $name - * @param string $fieldType - * @param string $value - * @return string - */ protected function generateMetaTagsString(string $name, string $fieldType, string $value): string { return sprintf( diff --git a/src/MetaTags/SwiftypeMetaTagDescription.php b/src/MetaTags/SwiftypeMetaTagDescription.php index 995cf92..59f5b86 100644 --- a/src/MetaTags/SwiftypeMetaTagDescription.php +++ b/src/MetaTags/SwiftypeMetaTagDescription.php @@ -2,11 +2,6 @@ namespace Ichaber\SSSwiftype\MetaTags; -/** - * Class SwiftypeMetaTagDescription - * - * @package Ichaber\SSSwiftype\MetaTags - */ class SwiftypeMetaTagDescription extends SwiftypeMetaTag { /** diff --git a/src/MetaTags/SwiftypeMetaTagInterface.php b/src/MetaTags/SwiftypeMetaTagInterface.php index cf71f29..011de7a 100644 --- a/src/MetaTags/SwiftypeMetaTagInterface.php +++ b/src/MetaTags/SwiftypeMetaTagInterface.php @@ -11,16 +11,8 @@ * and I would just get php errors any time I tried to instantiate a MetaTag class. * * Moving them into the same namespace was the only way I was able to move forward without going down a rabbit hole. - * - * Interface SwiftypeMetaTagInterface - * - * @package Ichaber\SSSwiftype\Interfaces */ interface SwiftypeMetaTagInterface { - /** - * @param DataObject $dataObject - * @return string|null - */ public function getMetaTagString(DataObject $dataObject): ?string; } diff --git a/src/MetaTags/SwiftypeMetaTagPublishedAt.php b/src/MetaTags/SwiftypeMetaTagPublishedAt.php index 4c08e17..204e3ff 100644 --- a/src/MetaTags/SwiftypeMetaTagPublishedAt.php +++ b/src/MetaTags/SwiftypeMetaTagPublishedAt.php @@ -2,11 +2,6 @@ namespace Ichaber\SSSwiftype\MetaTags; -/** - * Class SwiftypeMetaTagPublishedAt - * - * @package Ichaber\SSSwiftype\MetaTags - */ class SwiftypeMetaTagPublishedAt extends SwiftypeMetaTag { /** diff --git a/src/MetaTags/SwiftypeMetaTagRobots.php b/src/MetaTags/SwiftypeMetaTagRobots.php index 40e48e6..f9515b9 100644 --- a/src/MetaTags/SwiftypeMetaTagRobots.php +++ b/src/MetaTags/SwiftypeMetaTagRobots.php @@ -6,17 +6,8 @@ use SilverStripe\Core\Config\Config; use SilverStripe\ORM\DataObject; -/** - * Class SwiftypeMetaTagRobots - * - * @package Ichaber\SSSwiftype\MetaTags - */ class SwiftypeMetaTagRobots extends SwiftypeMetaTag { - /** - * @param DataObject $dataObject - * @return string|null - */ public function getMetaTagString(DataObject $dataObject): ?string { $value = $this->getFieldValue($dataObject); @@ -29,7 +20,6 @@ public function getMetaTagString(DataObject $dataObject): ?string } /** - * @param DataObject $dataObject * @return int|string|null */ protected function getFieldValue(DataObject $dataObject) diff --git a/src/MetaTags/SwiftypeMetaTagTitle.php b/src/MetaTags/SwiftypeMetaTagTitle.php index b878402..f456190 100644 --- a/src/MetaTags/SwiftypeMetaTagTitle.php +++ b/src/MetaTags/SwiftypeMetaTagTitle.php @@ -2,11 +2,6 @@ namespace Ichaber\SSSwiftype\MetaTags; -/** - * Class SwiftypeMetaTagTitle - * - * @package Ichaber\SSSwiftype\MetaTags - */ class SwiftypeMetaTagTitle extends SwiftypeMetaTag { /** diff --git a/src/MetaTags/SwiftypeMetaTagURL.php b/src/MetaTags/SwiftypeMetaTagURL.php index 4d22cb7..6a8e0bb 100644 --- a/src/MetaTags/SwiftypeMetaTagURL.php +++ b/src/MetaTags/SwiftypeMetaTagURL.php @@ -2,11 +2,6 @@ namespace Ichaber\SSSwiftype\MetaTags; -/** - * Class SwiftypeMetaTagURL - * - * @package Ichaber\SSSwiftype\MetaTags - */ class SwiftypeMetaTagURL extends SwiftypeMetaTag { /** diff --git a/src/Service/SwiftypeCrawler.php b/src/Service/SwiftypeCrawler.php index 0364ea8..8103622 100644 --- a/src/Service/SwiftypeCrawler.php +++ b/src/Service/SwiftypeCrawler.php @@ -10,10 +10,6 @@ /** * Credit: [Bernard Hamlin](https://github.com/blueo) and [Mojmir Fendek](https://github.com/mfendeksilverstripe) - * - * Class SwiftypeCrawler - * - * @package Ichaber\SSSwiftype\Service */ class SwiftypeCrawler { @@ -36,11 +32,6 @@ class SwiftypeCrawler */ private $messages = []; - /** - * Crawler constructor. - * - * @param Client|null $client - */ public function __construct(?Client $client = null) { if ($client === null) { @@ -53,13 +44,12 @@ public function __construct(?Client $client = null) /** * Crawls a page based on the locale * - * @param string $url * @param mixed|null $additionalData If set, we assume that you want to populate your Credentials through extension - * @return bool */ public function send(string $url, $additionalData = null): bool { $credentials = SwiftypeCredentials::create($additionalData); + if (!$credentials->isEnabled()) { $this->addMessage($credentials->getMessage()); $this->getLogger()->alert($credentials->getMessage()); @@ -114,6 +104,7 @@ public function send(string $url, $additionalData = null): bool // invalid response data $data = json_decode($contents, true); + if ($data && array_key_exists('error', $data)) { $message = sprintf( "Swiftype Crawl request failed - invalid response data \n%s\n%s\n%s", @@ -131,17 +122,11 @@ public function send(string $url, $additionalData = null): bool return true; } - /** - * @return array - */ public function getMessages(): array { return $this->messages; } - /** - * @return LoggerInterface - */ protected function getLogger(): LoggerInterface { if (!$this->logger) { @@ -151,9 +136,6 @@ protected function getLogger(): LoggerInterface return $this->logger; } - /** - * @param string $message - */ protected function addMessage(string $message): void { $this->messages[] = $message; diff --git a/src/Service/SwiftypeCredentials.php b/src/Service/SwiftypeCredentials.php index 5d473d6..a04db8c 100644 --- a/src/Service/SwiftypeCredentials.php +++ b/src/Service/SwiftypeCredentials.php @@ -10,10 +10,6 @@ /** * Credit: [Bernard Hamlin](https://github.com/blueo) and [Mojmir Fendek](https://github.com/mfendeksilverstripe) - * - * Class SwiftypeCredentials - * - * @package Ichaber\SSSwiftype\Service */ class SwiftypeCredentials { @@ -50,81 +46,51 @@ class SwiftypeCredentials */ private $message; - /** - * @return bool - */ public function isEnabled(): bool { return $this->enabled; } - /** - * @param bool|null $enabled - */ public function setEnabled(?bool $enabled): void { $this->enabled = (bool) $enabled; } - /** - * @return string|null - */ public function getEngineSlug(): ?string { return $this->engineSlug; } - /** - * @param string|null $engineSlug - */ public function setEngineSlug(?string $engineSlug): void { $this->engineSlug = $engineSlug; } - /** - * @return string|null - */ public function getDomainID(): ?string { return $this->domainID; } - /** - * @param string|null $domainID - */ public function setDomainID(?string $domainID): void { $this->domainID = $domainID; } - /** - * @return string|null - */ public function getAPIKey(): ?string { return $this->apiKey; } - /** - * @param string|null $apiKey - */ public function setAPIKey(?string $apiKey): void { $this->apiKey = $apiKey; } - /** - * @return string|null - */ public function getMessage(): ?string { return $this->message; } - /** - * @param string $message - */ public function setMessage(string $message): void { $this->message = $message; @@ -134,7 +100,6 @@ public function setMessage(string $message): void * Gets the Swiftype credentials * * @param mixed|null $additionalData If set, we assume that you want to populate your Credentials through extension - * @return void */ public function __construct($additionalData = null) { @@ -191,9 +156,6 @@ public function __construct($additionalData = null) } } - /** - * @param string $message - */ protected function disable(string $message): void { $trace = debug_backtrace(); @@ -205,9 +167,6 @@ protected function disable(string $message): void $this->setEnabled(false); } - /** - * @return LoggerInterface - */ protected function getLogger(): LoggerInterface { if (!$this->logger) { diff --git a/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php b/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php index b75aa37..9210def 100644 --- a/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php +++ b/tests/php/Extensions/SwiftypeMetaTagContentExtensionTest.php @@ -69,7 +69,7 @@ public function testMetaTagOutput(): void /** * @throws Exception */ - public function testMetaTagsReturnsEmptyByDefault() + public function testMetaTagsReturnsEmptyByDefault(): void { $page = new SwiftypeSiteTree(); /** @var DBHTMLText $tags */ @@ -80,7 +80,7 @@ public function testMetaTagsReturnsEmptyByDefault() /** * @throws Exception */ - public function testMetaTagsReturnsConfiguredTags() + public function testMetaTagsReturnsConfiguredTags(): void { $page = new SwiftypeSiteTree(); $page->MetaDescription = 'My description'; @@ -91,6 +91,6 @@ public function testMetaTagsReturnsConfiguredTags() /** @var DBHTMLText $tags */ $tags = $page->getSwiftypeMetaTags(); $this->assertNotEmpty($tags->getValue()); - $this->assertContains($page->MetaDescription, $tags->getValue()); + $this->assertStringContainsString($page->MetaDescription, $tags->getValue()); } } diff --git a/tests/php/Service/SwiftypeCredentialsTest.php b/tests/php/Service/SwiftypeCredentialsTest.php index 1a5d208..7015987 100644 --- a/tests/php/Service/SwiftypeCredentialsTest.php +++ b/tests/php/Service/SwiftypeCredentialsTest.php @@ -67,7 +67,7 @@ public function testNoEngineSlug(): void $credentials = SwiftypeCredentials::create(); $this->assertFalse($credentials->isEnabled()); - $this->assertContains('Swiftype Engine Slug value has not been set', $credentials->getMessage()); + $this->assertStringContainsString('Swiftype Engine Slug value has not been set', $credentials->getMessage()); } /** @@ -88,7 +88,7 @@ public function testNoDomainID(): void $credentials = SwiftypeCredentials::create(); $this->assertFalse($credentials->isEnabled()); - $this->assertContains('Swiftype Domain ID has not been set', $credentials->getMessage()); + $this->assertStringContainsString('Swiftype Domain ID has not been set', $credentials->getMessage()); } /** @@ -109,6 +109,6 @@ public function testNoApiKey(): void $credentials = SwiftypeCredentials::create(); $this->assertFalse($credentials->isEnabled()); - $this->assertContains('Swiftype API Key has not been set', $credentials->getMessage()); + $this->assertStringContainsString('Swiftype API Key has not been set', $credentials->getMessage()); } }