From fb6999a4893f17a2e374274d2a4a03e6eebfe9ec Mon Sep 17 00:00:00 2001 From: Anoushka Jha Date: Thu, 13 Oct 2022 12:43:35 +0530 Subject: [PATCH 01/12] Added Code Analyser --- .github/workflows/codeql-analysis.yml | 20 ++++++++++++++++++++ composer.json | 6 +++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..734db04 --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,20 @@ +name: "CodeQL" + +on: [pull_request] +jobs: + lint: + name: CodeQL + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Run CodeQL + run: | + docker run --rm -v $PWD:/app composer sh -c \ + "composer install --profile --ignore-platform-reqs && composer check" \ No newline at end of file diff --git a/composer.json b/composer.json index 4ca896a..a90ad18 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "email": "torsten@appwrite.io" } ], + "scripts": { + "check": "./vendor/bin/phpstan analyse --level max src tests" + }, "autoload": { "psr-4": {"Utopia\\Analytics\\": "src/Analytics"} }, @@ -24,6 +27,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" + "vimeo/psalm": "4.0.1", + "phpstan/phpstan": "1.9.x-dev" } } From 73c2f6e842868c4e785f471ecd6a451d65921cff Mon Sep 17 00:00:00 2001 From: Anoushka Jha <95405559+BabyElias@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:36:32 +0530 Subject: [PATCH 02/12] Implemented Code Analyser --- .github/workflows/codeql-analysis.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..2793d4a --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,20 @@ +name: "CodeQL" + +on: [pull_request] +jobs: + lint: + name: CodeQL + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Run CodeQL + run: | + docker run --rm -v $PWD:/app composer sh -c \ + "composer install --profile --ignore-platform-reqs && composer check" From 281d9c7a84ec17cb02672b8311cce4cd00a0caa3 Mon Sep 17 00:00:00 2001 From: Anoushka Jha <95405559+BabyElias@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:37:29 +0530 Subject: [PATCH 03/12] Update composer.json --- composer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/composer.json b/composer.json index 4ca896a..971401b 100644 --- a/composer.json +++ b/composer.json @@ -15,6 +15,9 @@ "email": "torsten@appwrite.io" } ], + "scripts": { + "check": "./vendor/bin/phpstan analyse --level max src tests" + }, "autoload": { "psr-4": {"Utopia\\Analytics\\": "src/Analytics"} }, From 34fa5eee0306dfa04d10d2eba9b044256ac9016e Mon Sep 17 00:00:00 2001 From: Anoushka Jha <95405559+BabyElias@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:37:49 +0530 Subject: [PATCH 04/12] Update composer.json --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 971401b..425329f 100644 --- a/composer.json +++ b/composer.json @@ -27,6 +27,7 @@ }, "require-dev": { "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" + "vimeo/psalm": "4.0.1", + "phpstan/phpstan": "1.9.x-dev" } } From b0d64b72720ca1ac28f3b9be932c2d1ff60cad04 Mon Sep 17 00:00:00 2001 From: Anoushka Jha <95405559+BabyElias@users.noreply.github.com> Date: Thu, 13 Oct 2022 15:43:13 +0530 Subject: [PATCH 05/12] Documentation update --- .github/ISSUE_TEMPLATE/bug.yaml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml index 381c75d..66755f6 100644 --- a/.github/ISSUE_TEMPLATE/bug.yaml +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -51,9 +51,8 @@ body: label: "🐘 PHP Version" description: "What version of PHP are you running?" options: - - PHP 7.3.x - - PHP 7.4.x - - Different version (specify in environment) + - PHP 8.0 + - type: dropdown id: operating-system attributes: From 1d0c4ca6f58739956dd589a7d6da1ad3f67c2c90 Mon Sep 17 00:00:00 2001 From: Anoushka Jha <95405559+BabyElias@users.noreply.github.com> Date: Fri, 14 Oct 2022 11:09:02 +0530 Subject: [PATCH 06/12] Reduced testing to level 6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 425329f..a3f4684 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ } ], "scripts": { - "check": "./vendor/bin/phpstan analyse --level max src tests" + "check": "./vendor/bin/phpstan analyse --level 6 src tests" }, "autoload": { "psr-4": {"Utopia\\Analytics\\": "src/Analytics"} From 1a7390f171a7e9c6493557c4f31df4044479b6f0 Mon Sep 17 00:00:00 2001 From: Anoushka Jha <95405559+BabyElias@users.noreply.github.com> Date: Fri, 14 Oct 2022 11:30:01 +0530 Subject: [PATCH 07/12] Corrected issues --- src/Analytics/Adapter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Analytics/Adapter.php b/src/Analytics/Adapter.php index 048bbcd..564bded 100644 --- a/src/Analytics/Adapter.php +++ b/src/Analytics/Adapter.php @@ -45,7 +45,7 @@ abstract public function getName(): string; /** * Global Headers * - * @var array + * @var array */ protected $headers = [ 'Content-Type' => '', @@ -133,7 +133,7 @@ public function createEvent(Event $event): bool * @return array|string * @throws \Exception */ - public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string + public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string { $headers = array_merge($this->headers, $headers); $ch = curl_init((str_contains($path, 'http') ? $path : $this->endpoint . $path . (($method == 'GET' && !empty($params)) ? '?' . http_build_query($params) : ''))); @@ -217,7 +217,7 @@ public function call(string $method, string $path = '', array $headers = array() * * @param array $data * @param string $prefix - * @return array + * @return array */ protected function flatten(array $data, string $prefix = ''): array { $output = []; @@ -249,4 +249,4 @@ protected function logError(Exception $e) { Console::error('[Error] File: ' . $e->getFile()); Console::error('[Error] Line: ' . $e->getLine()); } -} \ No newline at end of file +} From a27c48760fc7729c5ef47aceb4ab942e4f43c386 Mon Sep 17 00:00:00 2001 From: Anoushka Jha Date: Fri, 14 Oct 2022 11:33:49 +0530 Subject: [PATCH 08/12] Revert "Corrected issues" This reverts commit 1a7390f171a7e9c6493557c4f31df4044479b6f0. --- src/Analytics/Adapter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Analytics/Adapter.php b/src/Analytics/Adapter.php index 564bded..048bbcd 100644 --- a/src/Analytics/Adapter.php +++ b/src/Analytics/Adapter.php @@ -45,7 +45,7 @@ abstract public function getName(): string; /** * Global Headers * - * @var array + * @var array */ protected $headers = [ 'Content-Type' => '', @@ -133,7 +133,7 @@ public function createEvent(Event $event): bool * @return array|string * @throws \Exception */ - public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string + public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string { $headers = array_merge($this->headers, $headers); $ch = curl_init((str_contains($path, 'http') ? $path : $this->endpoint . $path . (($method == 'GET' && !empty($params)) ? '?' . http_build_query($params) : ''))); @@ -217,7 +217,7 @@ public function call(string $method, string $path = '', array $headers = array() * * @param array $data * @param string $prefix - * @return array + * @return array */ protected function flatten(array $data, string $prefix = ''): array { $output = []; @@ -249,4 +249,4 @@ protected function logError(Exception $e) { Console::error('[Error] File: ' . $e->getFile()); Console::error('[Error] Line: ' . $e->getLine()); } -} +} \ No newline at end of file From 1058a5ff9b7fac2c1e4e4600e6bf8664ae2ac64a Mon Sep 17 00:00:00 2001 From: Anoushka Jha Date: Fri, 14 Oct 2022 12:19:23 +0530 Subject: [PATCH 09/12] Made Corrections --- src/Analytics/Adapter.php | 42 ++++++++--------- src/Analytics/Adapter/ActiveCampaign.php | 58 ++++++++++++------------ src/Analytics/Adapter/Plausible.php | 20 ++++---- src/Analytics/Event.php | 38 ++++++++-------- tests/Analytics/AnalyticsTest.php | 36 +++++++-------- 5 files changed, 97 insertions(+), 97 deletions(-) diff --git a/src/Analytics/Adapter.php b/src/Analytics/Adapter.php index 048bbcd..ffb15e1 100644 --- a/src/Analytics/Adapter.php +++ b/src/Analytics/Adapter.php @@ -30,14 +30,14 @@ abstract class Adapter /** * The IP address to forward to Plausible - * + * * @var string */ protected string $clientIP; /** * Gets the name of the adapter. - * + * * @return string */ abstract public function getName(): string; @@ -45,7 +45,7 @@ abstract public function getName(): string; /** * Global Headers * - * @var array + * @var array */ protected $headers = [ 'Content-Type' => '', @@ -53,7 +53,7 @@ abstract public function getName(): string; /** * Enables tracking for this instance. - * + * * @return void */ public function enable(): void @@ -63,7 +63,7 @@ public function enable(): void /** * Disables tracking for this instance. - * + * * @return void */ public function disable(): void @@ -73,7 +73,7 @@ public function disable(): void /** * Send the event to the adapter. - * + * * @param Event $event * @return bool */ @@ -81,9 +81,9 @@ public abstract function send(Event $event): bool; /** * Sets the client IP address. - * + * * @param string $ip The IP address to use. - * + * * @return self */ public function setClientIP(string $clientIP): self @@ -94,9 +94,9 @@ public function setClientIP(string $clientIP): self /** * Sets the client user agent. - * + * * @param string $userAgent The user agent to use. - * + * * @return self */ public function setUserAgent(string $userAgent): self @@ -107,7 +107,7 @@ public function setUserAgent(string $userAgent): self /** * Creates an Event on the remote analytics platform. - * + * * @param Event $event * @return bool */ @@ -128,12 +128,12 @@ public function createEvent(Event $event): bool * * @param string $method * @param string $path - * @param array $params - * @param array $headers - * @return array|string + * @param array $params + * @param array $headers + * @return array|string * @throws \Exception */ - public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string + public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string { $headers = array_merge($this->headers, $headers); $ch = curl_init((str_contains($path, 'http') ? $path : $this->endpoint . $path . (($method == 'GET' && !empty($params)) ? '?' . http_build_query($params) : ''))); @@ -187,7 +187,7 @@ public function call(string $method, string $path = '', array $headers = array() $responseType = $responseHeaders['Content-Type'] ?? ''; $responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); - + switch(substr($responseType, 0, strpos($responseType, ';'))) { case 'application/json': $responseBody = json_decode($responseBody, true); @@ -197,7 +197,7 @@ public function call(string $method, string $path = '', array $headers = array() if (curl_errno($ch)) { throw new \Exception(curl_error($ch)); } - + curl_close($ch); if($responseStatus >= 400) { @@ -215,11 +215,11 @@ public function call(string $method, string $path = '', array $headers = array() /** * Flatten params array to PHP multiple format * - * @param array $data + * @param array $data * @param string $prefix * @return array */ - protected function flatten(array $data, string $prefix = ''): array { + protected function flatten(array $data, string $prefix = ''): array { $output = []; foreach($data as $key => $value) { @@ -238,7 +238,7 @@ protected function flatten(array $data, string $prefix = ''): array { /** * Log Error - * + * * @param Exception $e * @return void */ @@ -249,4 +249,4 @@ protected function logError(Exception $e) { Console::error('[Error] File: ' . $e->getFile()); Console::error('[Error] Line: ' . $e->getLine()); } -} \ No newline at end of file +} diff --git a/src/Analytics/Adapter/ActiveCampaign.php b/src/Analytics/Adapter/ActiveCampaign.php index d747daa..06c6fb8 100644 --- a/src/Analytics/Adapter/ActiveCampaign.php +++ b/src/Analytics/Adapter/ActiveCampaign.php @@ -48,7 +48,7 @@ class ActiveCampaign extends Adapter /** * Gets the name of the adapter. - * + * * @return string */ public function getName(): string @@ -59,7 +59,7 @@ public function getName(): string /** * Checks if a contact exists by the email ID. Returns the User ID if it exists and false if it doesn't. - * + * * @param string $email * @return bool|int */ @@ -85,7 +85,7 @@ public function contactExists(string $email): bool|int /** * Create a contact - * + * * @param string $email * @param string $firstName * @param string $lastName @@ -114,13 +114,13 @@ public function createContact(string $email, string $firstName = '', string $las /** * Update contact - * + * * @param string $contactId * @param string $email * @param string $firstName * @param string $lastName * @param string $phone - * + * * @return bool */ public function updateContact(string $contactId, string $email, string $firstName = '', string $lastName = '', string $phone = ''): bool @@ -144,9 +144,9 @@ public function updateContact(string $contactId, string $email, string $firstNam } } - /** - * Delete a contact - * + /** + * Delete a contact + * * @param string $email * @return bool */ @@ -168,7 +168,7 @@ public function deleteContact(string $email): bool { /** * Account Exists - * + * * @param string $name * @return bool|int */ @@ -192,12 +192,12 @@ public function accountExists(string $name): bool|int /** * Create an account - * + * * @param string $name * @param string $url * @param int $ownerId - * @param array $fields - * + * @param array $fields + * * @return bool */ public function createAccount(string $name, string $url = '', int $ownerId = 1, array $fields = []): bool @@ -224,13 +224,13 @@ public function createAccount(string $name, string $url = '', int $ownerId = 1, /** * Update an account - * + * * @param string $accountId * @param string $name * @param string $url * @param int $ownerId - * @param array $fields - * + * @param array $fields + * * @return bool */ public function updateAccount(string $accountId, string $name, string $url = '', int $ownerId = 1, array $fields = []): bool @@ -257,9 +257,9 @@ public function updateAccount(string $accountId, string $name, string $url = '', /** * Delete an account - * + * * @param string $accountId - * + * * @return bool */ public function deleteAccount(string $accountId): bool @@ -275,13 +275,13 @@ public function deleteAccount(string $accountId): bool /** * Sync an association - * + * * Creates an association if it doesn't exist and updates it if it does - * + * * @param string $accountId * @param string $contactId * @param string $role - * + * * @return bool */ public function syncAssociation(string $accountId, string $contactId, string $role = ''): bool @@ -330,11 +330,11 @@ public function syncAssociation(string $accountId, string $contactId, string $ro } /** - * @param string $key + * @param string $key * @param string $actId * @param string $apiKey * @param string $organisationId - * + * * @return ActiveCampaign */ public function __construct(string $key, string $actId, string $apiKey, string $organisationId) @@ -351,11 +351,11 @@ public function __construct(string $key, string $actId, string $apiKey, string $ /** * Creates an Event on the remote analytics platform. - * + * * @param Event $event * @return bool */ - public function send(Event $event): bool + public function send(Event $event): bool { if (!$this->enabled) { return false; @@ -368,7 +368,7 @@ public function send(Event $event): bool 'eventdata' => json_encode($event->getProps()), 'visit' => json_encode(['email' => $event->getProp('email')]), ]; - + $query = array_filter($query, fn($value) => !is_null($value) && $value !== ''); $this->call('POST', 'https://trackcmp.net/event', [], $query); // Active Campaign event URL, Refer to https://developers.activecampaign.com/reference/track-event/ for more details @@ -377,9 +377,9 @@ public function send(Event $event): bool /** * Sets the client IP address. - * + * * @param string $ip The IP address to use. - * + * * @return self */ public function setClientIP(string $clientIP): self @@ -389,9 +389,9 @@ public function setClientIP(string $clientIP): self /** * Sets the client user agent. - * + * * @param string $userAgent The user agent to use. - * + * * @return self */ public function setUserAgent(string $userAgent): self diff --git a/src/Analytics/Adapter/Plausible.php b/src/Analytics/Adapter/Plausible.php index 2984e7b..1a8972b 100644 --- a/src/Analytics/Adapter/Plausible.php +++ b/src/Analytics/Adapter/Plausible.php @@ -29,7 +29,7 @@ class Plausible extends Adapter /** * Global Headers * - * @var array + * @var array */ protected $headers = []; @@ -42,15 +42,15 @@ class Plausible extends Adapter /** * Domain to use for events - * + * * @var string */ protected string $domain; - + /** * Gets the name of the adapter. - * + * * @return string */ public function getName(): string @@ -60,12 +60,12 @@ public function getName(): string /** * Constructor. - * + * * @param string $domain The domain to use for events * @param string $apiKey The API key to use for requests * @param string $useragent The useragent to use for requests * @param string $clientIP The IP address to forward to Plausible - * + * * @return Plausible */ public function __construct(string $domain, string $apiKey, string $useragent, string $clientIP) @@ -78,9 +78,9 @@ public function __construct(string $domain, string $apiKey, string $useragent, s /** * Sends an event to Plausible. - * + * * @param Event $event The event to send. - * + * * @return bool */ public function send(Event $event): bool @@ -112,9 +112,9 @@ public function send(Event $event): bool /** * Provision a goal for the given event. - * + * * @param string $eventName The name of the event. - * + * * @return bool */ private function provisionGoal(string $eventName): bool diff --git a/src/Analytics/Event.php b/src/Analytics/Event.php index d1ab15a..7de4621 100644 --- a/src/Analytics/Event.php +++ b/src/Analytics/Event.php @@ -3,7 +3,7 @@ namespace Utopia\Analytics; class Event { - + /** * @var string (required) */ @@ -25,13 +25,13 @@ class Event { private ?string $value = null; /** - * @var array[] + * @var array */ private array $props = []; /** * Get the type of event - * + * * @return string */ public function getType(): string { @@ -40,7 +40,7 @@ public function getType(): string { /** * Set the type of event - * + * * @param string $type * @return Event */ @@ -51,7 +51,7 @@ public function setType(string $type): self { /** * Get the URL of the event - * + * * @return string */ public function getUrl(): string { @@ -60,7 +60,7 @@ public function getUrl(): string { /** * Set the URL of the event - * + * * @param string $url * @return Event */ @@ -71,7 +71,7 @@ public function setUrl(string $url): self { /** * Get the name of the event - * + * * @return string */ public function getName(): string { @@ -80,7 +80,7 @@ public function getName(): string { /** * Set the name of the event - * + * * @param string $name * @return Event */ @@ -91,7 +91,7 @@ public function setName(string $name): self { /** * Get the value of the event - * + * * @return string|null */ public function getValue(): ?string { @@ -100,7 +100,7 @@ public function getValue(): ?string { /** * Set the value of the event - * + * * @param string|null $value * @return Event */ @@ -111,16 +111,16 @@ public function setValue(?string $value): self { /** * Get the properties of the event - * - * @return array[] + * + * @return array */ - public function getProps(): array { + public function getProps(): array { return $this->props; } /** * Adds extra properties to the event - * + * * @param string $key * @param string $value * @return Event @@ -132,7 +132,7 @@ public function addProp(string $key, string $value): self { /** * Removes a property from the event - * + * * @param string $key * @return Event */ @@ -145,7 +145,7 @@ public function removeProp(string $key): self { /** * Get a property from the event - * + * * @param string $key * @return string|null */ @@ -158,12 +158,12 @@ public function getProp(string $key): ?string { /** * Set the properties of the event - * - * @param array[] $props + * + * @param array $props * @return Event */ public function setProps(array $props): self { $this->props = $props; return $this; } -} \ No newline at end of file +} diff --git a/tests/Analytics/AnalyticsTest.php b/tests/Analytics/AnalyticsTest.php index 7a6250a..13fe3f9 100644 --- a/tests/Analytics/AnalyticsTest.php +++ b/tests/Analytics/AnalyticsTest.php @@ -32,16 +32,16 @@ public function setUp(): void { $this->ga = new GoogleAnalytics(getenv("GA_TID"), getenv("GA_CID")); $this->ac = new ActiveCampaign( - getenv("AC_KEY"), + getenv("AC_KEY"), getenv("AC_ACTID"), getenv("AC_APIKEY"), getenv("AC_ORGID")); - $this->pa = new Plausible(getenv("PA_DOMAIN"), getenv("PA_APIKEY"), + $this->pa = new Plausible(getenv("PA_DOMAIN"), getenv("PA_APIKEY"), "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36", "192.168.0.1"); $this->orbit = new Orbit(getenv("OR_WORKSPACEID"), getenv("OR_APIKEY"), "Utopia Testing Suite"); } - public function testGoogleAnalytics() + public function testGoogleAnalytics(): void { // Use Measurement Protocol Validation Server for testing. $this->ga->endpoint = "https://www.google-analytics.com/debug/collect"; @@ -66,7 +66,7 @@ public function testGoogleAnalytics() $this->assertFalse($this->ga->createEvent($normalEvent)); } - public function testPlausible() + public function testPlausible(): void { $pageviewEvent = new Event(); $pageviewEvent @@ -77,16 +77,16 @@ public function testPlausible() $normalEvent->setType('myCoolEvent') ->setUrl('https://www.appwrite.io/docs/myCoolEvent123') ->setProps(['category' => 'coolEvent']);; - + $this->assertTrue($this->pa->createEvent($pageviewEvent)); $this->assertTrue($this->pa->createEvent($normalEvent)); - + $this->pa->disable(); $this->assertFalse($this->pa->createEvent($pageviewEvent)); $this->assertFalse($this->pa->createEvent($normalEvent)); } - public function testActiveCampaignCreateAccount() { + public function testActiveCampaignCreateAccount(): void { $this->assertTrue($this->ac->createAccount( 'Appwrite', 'appwrite.io', @@ -109,7 +109,7 @@ public function testActiveCampaignGetAccount() { ]; } - public function testActiveCampaignCreateContact() { + public function testActiveCampaignCreateContact(): void { $this->assertTrue($this->ac->createContact('test@test.com', 'Paul', 'Van Doren')); } @@ -129,7 +129,7 @@ public function testActiveCampaignGetContact($data) { /** * @depends testActiveCampaignGetContact */ - public function testActiveCampaignSyncAsociation($data) { + public function testActiveCampaignSyncAsociation($data): void{ $this->assertTrue($this->ac->syncAssociation($data['accountID'], $data['contactID'], 'Owner')); $this->assertTrue($this->ac->syncAssociation($data['accountID'], $data['contactID'], 'Software Developer')); } @@ -137,33 +137,33 @@ public function testActiveCampaignSyncAsociation($data) { /** * @depends testActiveCampaignGetContact */ - public function testActiveCampaignUpdateContact($data) { + public function testActiveCampaignUpdateContact($data): void { $this->assertTrue($this->ac->updateContact($data['contactID'], 'test@test.com', '', '', '7223224241')); } - public function testActiveCampaignDeleteContact() { + public function testActiveCampaignDeleteContact(): void { $this->assertTrue($this->ac->deleteContact('test@test.com')); } /** * @depends testActiveCampaignGetAccount */ - public function testActiveCampaignUpdateAccount($data) { + public function testActiveCampaignUpdateAccount($data): void { $this->assertTrue($this->ac->updateAccount( - $data['accountID'], - 'Utopia', - 'utopia.com', + $data['accountID'], + 'Utopia', + 'utopia.com', 1)); } /** * @depends testActiveCampaignGetAccount */ - public function testActiveCampaignDeleteAccount($data) { + public function testActiveCampaignDeleteAccount($data): void { $this->assertTrue($this->ac->deleteAccount($data['accountID'])); } - public function testOrbit() { + public function testOrbit(): void { $event = new Event(); $event->setType('testEvent') ->setName('testEvent') @@ -172,4 +172,4 @@ public function testOrbit() { $this->assertTrue($this->orbit->send($event)); } -} \ No newline at end of file +} From d0180c06af20f1ae84bfd5a0bca85658cbbc43b4 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 16 Feb 2023 13:45:57 +0000 Subject: [PATCH 10/12] feat: resolve merge conflicts --- tests/Analytics/AnalyticsTest.php | 70 ------------------------------- 1 file changed, 70 deletions(-) diff --git a/tests/Analytics/AnalyticsTest.php b/tests/Analytics/AnalyticsTest.php index 307962a..c8742d0 100644 --- a/tests/Analytics/AnalyticsTest.php +++ b/tests/Analytics/AnalyticsTest.php @@ -42,15 +42,6 @@ public function setUp(): void { $this->ga = new GoogleAnalytics(App::getEnv("GA_TID"), App::getEnv("GA_CID")); $this->ac = new ActiveCampaign( -<<<<<<< HEAD - getenv("AC_KEY"), - getenv("AC_ACTID"), - getenv("AC_APIKEY"), - getenv("AC_ORGID")); - $this->pa = new Plausible(getenv("PA_DOMAIN"), getenv("PA_APIKEY"), - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36", "192.168.0.1"); - $this->orbit = new Orbit(getenv("OR_WORKSPACEID"), getenv("OR_APIKEY"), "Utopia Testing Suite"); -======= App::getEnv("AC_KEY"), App::getEnv("AC_ACTID"), App::getEnv("AC_APIKEY"), @@ -58,7 +49,6 @@ public function setUp(): void ); $this->pa = new Plausible(App::getEnv("PA_DOMAIN"), App::getEnv("PA_APIKEY"), "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36", "192.168.0.1"); $this->orbit = new Orbit(App::getEnv("OR_WORKSPACEID"), App::getEnv("OR_APIKEY"), "Utopia Testing Suite"); ->>>>>>> f0306021de06277309d2f121bc1860a639c852b5 } public function testGoogleAnalytics(): void @@ -92,45 +82,6 @@ public function testPlausible(): void ->setUrl('https://www.appwrite.io/docs/pageview123'); $normalEvent = new Event(); -<<<<<<< HEAD - $normalEvent->setType('myCoolEvent') - ->setUrl('https://www.appwrite.io/docs/myCoolEvent123') - ->setProps(['category' => 'coolEvent']);; - - $this->assertTrue($this->pa->createEvent($pageviewEvent)); - $this->assertTrue($this->pa->createEvent($normalEvent)); - - $this->pa->disable(); - $this->assertFalse($this->pa->createEvent($pageviewEvent)); - $this->assertFalse($this->pa->createEvent($normalEvent)); - } - - public function testActiveCampaignCreateAccount(): void { - $this->assertTrue($this->ac->createAccount( - 'Appwrite', - 'appwrite.io', - 1, - [ - [ - 'customFieldId' => 1, - 'fieldValue' => 'Hello World!' - ], - ] - )); - } - - public function testActiveCampaignGetAccount() { - $accountID = $this->ac->accountExists('Appwrite'); - $this->assertIsNumeric($accountID); - - return [ - 'accountID' => $accountID, - ]; - } - - public function testActiveCampaignCreateContact(): void { - $this->assertTrue($this->ac->createContact('test@test.com', 'Paul', 'Van Doren')); -======= $normalEvent->setType('testEvent') ->setName('testEvent'.chr(mt_rand(97, 122)).substr(md5(time()), 1, 5)) ->setUrl('https://www.appwrite.io/docs/installation') @@ -143,7 +94,6 @@ public function testActiveCampaignCreateContact(): void { public function testActiveCampaignCreateContact() { $this->assertTrue($this->ac->createContact('analytics2@utopiaphp.com', 'Analytics', 'Utopia')); ->>>>>>> f0306021de06277309d2f121bc1860a639c852b5 } public function testActiveCampaignGetContact() { @@ -162,9 +112,6 @@ public function testActiveCampaignCreateAccount() { /** * @depends testActiveCampaignGetContact */ -<<<<<<< HEAD - public function testActiveCampaignSyncAsociation($data): void{ -======= public function testActiveCampaignGetAccount($data) { $accountID = $this->ac->accountExists('Example Account 1'); $this->assertIsNumeric($accountID); @@ -178,7 +125,6 @@ public function testActiveCampaignGetAccount($data) { * @depends testActiveCampaignGetAccount */ public function testActiveCampaignSyncAsociation($data) { ->>>>>>> f0306021de06277309d2f121bc1860a639c852b5 $this->assertTrue($this->ac->syncAssociation($data['accountID'], $data['contactID'], 'Owner')); $this->assertTrue($this->ac->syncAssociation($data['accountID'], $data['contactID'], 'Software Developer')); } @@ -186,21 +132,12 @@ public function testActiveCampaignSyncAsociation($data) { /** * @depends testActiveCampaignGetContact */ -<<<<<<< HEAD - public function testActiveCampaignUpdateContact($data): void { - $this->assertTrue($this->ac->updateContact($data['contactID'], 'test@test.com', '', '', '7223224241')); - } - - public function testActiveCampaignDeleteContact(): void { - $this->assertTrue($this->ac->deleteContact('test@test.com')); -======= public function testActiveCampaignUpdateContact($data) { $this->assertTrue($this->ac->updateContact($data['contactID'], 'analytics2@utopiaphp.com', '', '', '7223224241')); } public function testActiveCampaignDeleteContact() { $this->assertTrue($this->ac->deleteContact('analytics2@utopiaphp.com')); ->>>>>>> f0306021de06277309d2f121bc1860a639c852b5 } /** @@ -221,9 +158,6 @@ public function testActiveCampaignDeleteAccount($data): void { $this->assertTrue($this->ac->deleteAccount($data['accountID'])); } -<<<<<<< HEAD - public function testOrbit(): void { -======= public function testActiveCampaign() { $this->assertTrue($this->ac->createContact('analytics@utopiaphp.com', 'Analytics', 'Utopia')); @@ -240,7 +174,6 @@ public function testActiveCampaign() { public function testOrbit(): void { ->>>>>>> f0306021de06277309d2f121bc1860a639c852b5 $event = new Event(); $event->setType('testEvent') ->setName('testEvent') @@ -250,8 +183,6 @@ public function testOrbit(): void $this->assertTrue($this->orbit->send($event)); $this->assertTrue($this->orbit->validate($event)); } -<<<<<<< HEAD -======= function testCleanup(): void { @@ -267,5 +198,4 @@ function testCleanup(): void $this->assertTrue($this->ac->deleteAccount($this->ac->accountExists('Example Account 1'))); } } ->>>>>>> f0306021de06277309d2f121bc1860a639c852b5 } From 17ebda0cbae0d0a5d6a5eca7bdca377a51f49193 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 16 Feb 2023 13:47:31 +0000 Subject: [PATCH 11/12] feat: review comments --- .github/ISSUE_TEMPLATE/bug.yaml | 1 + src/Analytics/Adapter.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug.yaml b/.github/ISSUE_TEMPLATE/bug.yaml index 66755f6..c039148 100644 --- a/.github/ISSUE_TEMPLATE/bug.yaml +++ b/.github/ISSUE_TEMPLATE/bug.yaml @@ -52,6 +52,7 @@ body: description: "What version of PHP are you running?" options: - PHP 8.0 + - Different version (specify in environment) - type: dropdown id: operating-system diff --git a/src/Analytics/Adapter.php b/src/Analytics/Adapter.php index 9e91523..39c1231 100644 --- a/src/Analytics/Adapter.php +++ b/src/Analytics/Adapter.php @@ -142,7 +142,7 @@ public function createEvent(Event $event): bool * @return array|string * @throws \Exception */ - public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array|string + public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array { $headers = array_merge($this->headers, $headers); $ch = curl_init((str_contains($path, 'http') ? $path : $this->endpoint . $path . (($method == 'GET' && !empty($params)) ? '?' . http_build_query($params) : ''))); From db8301e2e8cacc132c9c82ff4dbe10ce737b0bb1 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Thu, 16 Feb 2023 19:00:35 +0000 Subject: [PATCH 12/12] feat: phpstan fixes --- .travis.yml | 2 +- composer.json | 10 ----- src/Analytics/Adapter.php | 8 ++-- src/Analytics/Adapter/ActiveCampaign.php | 1 + src/Analytics/Adapter/Orbit.php | 2 +- src/Analytics/Adapter/Plausible.php | 1 + src/Analytics/Event.php | 2 +- tests/Analytics/AnalyticsTest.php | 56 +++++++++++++++++------- 8 files changed, 50 insertions(+), 32 deletions(-) diff --git a/.travis.yml b/.travis.yml index b441653..3fcd18b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ before_script: composer install --ignore-platform-reqs script: - vendor/bin/phpunit --configuration phpunit.xml -- vendor/bin/psalm --show-info=true +- vendor/bin/psalm --show-info=true \ No newline at end of file diff --git a/composer.json b/composer.json index e0385a5..cec5b85 100644 --- a/composer.json +++ b/composer.json @@ -5,16 +5,6 @@ "keywords": ["php","framework", "upf", "utopia", "analytics"], "license": "MIT", "minimum-stability": "stable", - "authors": [ - { - "name": "Eldad Fux", - "email": "eldad@appwrite.io" - }, - { - "name": "Torsten Dittmann", - "email": "torsten@appwrite.io" - } - ], "scripts": { "check": "./vendor/bin/phpstan analyse --level 6 src tests" }, diff --git a/src/Analytics/Adapter.php b/src/Analytics/Adapter.php index 39c1231..9c9e174 100644 --- a/src/Analytics/Adapter.php +++ b/src/Analytics/Adapter.php @@ -139,7 +139,8 @@ public function createEvent(Event $event): bool * @param string $path * @param array $params * @param array $headers - * @return array|string + * + * @return array * @throws \Exception */ public function call(string $method, string $path = '', array $headers = array(), array $params = array()): array @@ -226,9 +227,10 @@ public function call(string $method, string $path = '', array $headers = array() * * @param array $data * @param string $prefix - * @return array + * @return array */ - protected function flatten(array $data, string $prefix = ''): array { + protected function flatten(array $data, string $prefix = ''): array + { $output = []; foreach($data as $key => $value) { diff --git a/src/Analytics/Adapter/ActiveCampaign.php b/src/Analytics/Adapter/ActiveCampaign.php index ecd4036..0fc872d 100644 --- a/src/Analytics/Adapter/ActiveCampaign.php +++ b/src/Analytics/Adapter/ActiveCampaign.php @@ -54,6 +54,7 @@ public function getName(): string public function contactExists(string $email): bool|int { try { + $result = $this->call('GET', '/api/3/contacts', [], [ 'email' => $email ]); diff --git a/src/Analytics/Adapter/Orbit.php b/src/Analytics/Adapter/Orbit.php index 348f0a6..ec0bd50 100644 --- a/src/Analytics/Adapter/Orbit.php +++ b/src/Analytics/Adapter/Orbit.php @@ -107,7 +107,7 @@ public function send(Event $event): bool /** * Sets the client IP address. * - * @param string $ip The IP address to use. + * @param string $clientIP The IP address to use. * * @return self */ diff --git a/src/Analytics/Adapter/Plausible.php b/src/Analytics/Adapter/Plausible.php index 0b88ff0..bea618e 100644 --- a/src/Analytics/Adapter/Plausible.php +++ b/src/Analytics/Adapter/Plausible.php @@ -156,6 +156,7 @@ public function validate(Event $event): bool 'filters' => json_encode(["goal" => $event->getName()]), ]); + /** @var string $checkCreated */ $checkCreated = $this->call('GET', $validateURL, [ 'Content-Type' => '', 'Authorization' => 'Bearer ' . $this->apiKey diff --git a/src/Analytics/Event.php b/src/Analytics/Event.php index 3897e17..b93f49f 100644 --- a/src/Analytics/Event.php +++ b/src/Analytics/Event.php @@ -114,7 +114,7 @@ public function setValue(?string $value): self { * * @return array */ - public function getProps(): array { + public function getProps(): array { return $this->props; } diff --git a/tests/Analytics/AnalyticsTest.php b/tests/Analytics/AnalyticsTest.php index c8742d0..86c8411 100644 --- a/tests/Analytics/AnalyticsTest.php +++ b/tests/Analytics/AnalyticsTest.php @@ -12,16 +12,16 @@ class AnalyticsTest extends TestCase { - /** @var \Utopia\Analytics\Adapter\GoogleAnalytics $ga */ + /** @var GoogleAnalytics $ga */ public $ga; - /** @var \Utopia\Analytics\Adapter\ActiveCampaign|null $ac */ + /** @var ActiveCampaign|null $ac */ public $ac; - /** @var \Utopia\Analytics\Adapter\Plausible $pa */ + /** @var Plausible $pa */ public $pa; - /** @var \Utopia\Analytics\Adapter\Orbit $orbit */ + /** @var Orbit $orbit */ public $orbit; public function __construct() @@ -83,7 +83,7 @@ public function testPlausible(): void $normalEvent = new Event(); $normalEvent->setType('testEvent') - ->setName('testEvent'.chr(mt_rand(97, 122)).substr(md5(time()), 1, 5)) + ->setName('testEvent'.chr(mt_rand(97, 122)).substr(md5(strval(time())), 1, 5)) ->setUrl('https://www.appwrite.io/docs/installation') ->setProps(['category' => 'testEvent']);; @@ -92,11 +92,16 @@ public function testPlausible(): void $this->assertTrue($this->pa->validate($normalEvent)); } - public function testActiveCampaignCreateContact() { + public function testActiveCampaignCreateContact(): void + { $this->assertTrue($this->ac->createContact('analytics2@utopiaphp.com', 'Analytics', 'Utopia')); } - public function testActiveCampaignGetContact() { + /** + * @return array + */ + public function testActiveCampaignGetContact(): array + { $contactID = $this->ac->contactExists('analytics2@utopiaphp.com'); $this->assertIsNumeric($contactID); @@ -105,14 +110,20 @@ public function testActiveCampaignGetContact() { ]; } - public function testActiveCampaignCreateAccount() { - $this->assertTrue($this->ac->createAccount('Example Account 1', 'https://example.com', '1234567890')); + public function testActiveCampaignCreateAccount(): void + { + $this->assertTrue($this->ac->createAccount('Example Account 1', 'https://example.com', 1234567890)); } /** * @depends testActiveCampaignGetContact + * + * @param array $data + * + * @return array */ - public function testActiveCampaignGetAccount($data) { + public function testActiveCampaignGetAccount($data): array + { $accountID = $this->ac->accountExists('Example Account 1'); $this->assertIsNumeric($accountID); @@ -123,25 +134,34 @@ public function testActiveCampaignGetAccount($data) { /** * @depends testActiveCampaignGetAccount + * + * @param array $data */ - public function testActiveCampaignSyncAsociation($data) { + public function testActiveCampaignSyncAsociation($data): void + { $this->assertTrue($this->ac->syncAssociation($data['accountID'], $data['contactID'], 'Owner')); $this->assertTrue($this->ac->syncAssociation($data['accountID'], $data['contactID'], 'Software Developer')); } /** * @depends testActiveCampaignGetContact + * + * @param array $data */ - public function testActiveCampaignUpdateContact($data) { + public function testActiveCampaignUpdateContact($data): void + { $this->assertTrue($this->ac->updateContact($data['contactID'], 'analytics2@utopiaphp.com', '', '', '7223224241')); } - public function testActiveCampaignDeleteContact() { + public function testActiveCampaignDeleteContact(): void + { $this->assertTrue($this->ac->deleteContact('analytics2@utopiaphp.com')); } /** * @depends testActiveCampaignGetAccount + * + * @param array $data */ public function testActiveCampaignUpdateAccount($data): void { $this->assertTrue($this->ac->updateAccount( @@ -153,17 +173,21 @@ public function testActiveCampaignUpdateAccount($data): void { /** * @depends testActiveCampaignGetAccount + * + * @param array $data */ - public function testActiveCampaignDeleteAccount($data): void { + public function testActiveCampaignDeleteAccount($data): void + { $this->assertTrue($this->ac->deleteAccount($data['accountID'])); } - public function testActiveCampaign() { + public function testActiveCampaign(): void + { $this->assertTrue($this->ac->createContact('analytics@utopiaphp.com', 'Analytics', 'Utopia')); $event = new Event(); $event->setType('testEvent') - ->setName('testEvent'.chr(mt_rand(97, 122)).substr(md5(time()), 1, 5)) + ->setName('testEvent'.chr(mt_rand(97, 122)).substr(md5(strval(time())), 1, 5)) ->setUrl('https://www.appwrite.io/docs/installation') ->setProps(['category' => 'analytics:test', 'email' => 'analytics@utopiaphp.com', 'tags' => ['test', 'test2']]);