Skip to content

Commit 737d07d

Browse files
authored
Move support up to PHP 8+ (#27)
Updating supported PHP Versions to 8+ for future adaptability and type safety
2 parents 2343b6a + 06ab2d6 commit 737d07d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+564
-610
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,74 @@ on:
44
pull_request:
55
branches:
66
- "master"
7-
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.head_ref || github.run_id }}
10+
cancel-in-progress: true
811

912
jobs:
13+
validate-mergable:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: "Checkout"
17+
uses: actions/checkout@v3
18+
with:
19+
fetch-depth: 0
20+
21+
- name: "Validate Mergable"
22+
run: git merge origin/master --no-commit --ff-only
23+
1024
render-php:
25+
needs: validate-mergable
1126
runs-on: ${{ matrix.operating-system }}
27+
1228
strategy:
1329
max-parallel: 3
14-
fail-fast: false
30+
fail-fast: true
1531
matrix:
1632
operating-system: ["ubuntu-latest", "windows-latest"]
17-
php-versions: ["7.0", "7.1", "7.4", "8.0", "8.1"]
33+
php-versions: ["8.0", "8.1", "8.2"]
1834
phpunit-versions: ["latest"]
35+
1936
steps:
20-
- uses: actions/checkout@v3
37+
- name: "Checkout"
38+
uses: actions/checkout@v3
2139
with:
2240
fetch-depth: 0
23-
- run: git merge origin/master --no-commit --ff-only
24-
- uses: shivammathur/setup-php@v2
41+
42+
- name: "Setup PHP"
43+
uses: shivammathur/setup-php@v2
2544
with:
2645
php-version: ${{ matrix.php-versions }}
2746
extensions: mbstring, intl
2847
ini-values: post_max_size=256M, max_execution_time=180
29-
coverage: xdebug
48+
coverage: none
3049
tools: phpunit:${{ matrix.phpunit-versions }}
31-
- name: "Install"
32-
run: |
33-
composer update --no-install --with-all-dependencies
34-
composer install
35-
- name: "PHPUnit Tests"
36-
run: ./vendor/bin/phpunit
50+
51+
- name: "Composer State"
52+
run: composer update --no-install --with-all-dependencies
53+
54+
- name: "Composer Name Hash"
55+
id: composer-hash
56+
uses: KEINOS/gh-action-hash-for-cache@main
57+
with:
58+
path: ./composer.lock
59+
60+
- name: "Caching"
61+
id: cache-composer
62+
uses: actions/cache@v3
63+
with:
64+
path: vendor
65+
key: composer-${{ steps.composer-hash.outputs.hash }}
66+
restore-keys: composer-${{ steps.composer-hash.outputs.hash }}
67+
68+
- name: "Install Dependencies"
69+
if: ${{ steps.cache-composer.outputs.cache-hit != 'true' }}
70+
run: composer install
71+
72+
- name: "Linux: Restore Vendor Executable"
73+
if: matrix.operating-system == 'ubuntu-latest'
74+
run: chmod -R 0755 vendor
75+
76+
- name: "PHPUnit"
77+
run: ./vendor/bin/phpunit --testdox

.github/workflows/clear-cache.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: Clear all Github actions caches on sundays
2+
on:
3+
schedule:
4+
- cron: "0 0 * * 0"
5+
workflow_dispatch:
6+
7+
jobs:
8+
my-job:
9+
name: Delete all caches
10+
runs-on: ubuntu-20.04
11+
12+
steps:
13+
- name: Clear caches
14+
uses: easimon/wipe-cache@main

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PHP GA4
1+
# PHP GA4 | PHP 8+
22

33
PHP Wrapper for Google Analytics 4 Server Side Tracking of events.
44

@@ -8,17 +8,20 @@ PHP Wrapper for Google Analytics 4 Server Side Tracking of events.
88

99
`composer require alexwestergaard/php-ga4`
1010

11-
- [PHP GA4](#php-ga4)
11+
- [PHP GA4 | PHP 8+](#php-ga4--php-8)
1212
- [Events](#events)
1313
- [Default](#default)
1414
- [E-commerce](#e-commerce)
1515
- [Engagement / Gaming](#engagement--gaming)
16-
- [Frontend & Backend Communication](#frontend--backend-communication)
16+
- [Frontend \& Backend Communication](#frontend--backend-communication)
1717
- [Logged/Queued Events](#loggedqueued-events)
1818
- [Frontend to Backend communication](#frontend-to-backend-communication)
1919
- [Custom Events](#custom-events)
2020
- [Documentation](#documentation)
2121

22+
**LEGACY WARNING**
23+
- `PHP 7` should only use `1.0.*` versions of this library
24+
2225
## Events
2326

2427
This is a list of prebuilt events as shown in the documentation.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"license": "MIT",
1414
"authors": [
1515
{
16-
"name": "Alex Westergaard",
16+
"name": "Alex Ahlgreen Westergaard",
1717
"homepage": "https://aaw.nu",
1818
"role": "Developer"
1919
}
@@ -28,10 +28,10 @@
2828
}
2929
},
3030
"require": {
31-
"php": "^7.0|^8.0",
32-
"guzzlehttp/guzzle": "^6.0|^7.0"
31+
"php": "^8.0",
32+
"guzzlehttp/guzzle": "^7.0"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^6.0|^7.0|^8.0|^9.0"
35+
"phpunit/phpunit": "^9.0|^10.0"
3636
}
3737
}

src/Analytics.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function setUserId(string $id)
8484
/**
8585
* @param int|float $microOrUnix time() or microtime(true)
8686
*/
87-
public function setTimestamp($microOrUnix)
87+
public function setTimestamp(int|float $microOrUnix)
8888
{
8989
$secondInMicro = intval(strtr('1_000_000', ['_' => '']));
9090
$offsetLimit = strtotime('-3 days') * $secondInMicro;

src/Event/AddPaymentInfo.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
namespace AlexWestergaard\PhpGa4\Event;
44

5-
use AlexWestergaard\PhpGa4\GA4Exception;
6-
use AlexWestergaard\PhpGa4\Facade;
7-
use AlexWestergaard\PhpGa4\Model;
85
use AlexWestergaard\PhpGa4\Item;
6+
use AlexWestergaard\PhpGa4\Model;
7+
use AlexWestergaard\PhpGa4\Facade;
98

109
class AddPaymentInfo extends Model\Event implements Facade\AddPaymentInfo
1110
{
12-
protected $currency;
13-
protected $value;
14-
protected $coupon;
15-
protected $payment_type;
16-
protected $items = [];
11+
protected null|string $currency;
12+
protected null|int|float $value;
13+
protected null|string $coupon;
14+
protected null|string $payment_type;
15+
protected array $items = [];
1716

1817
public function getName(): string
1918
{
@@ -49,32 +48,25 @@ public function getRequiredParams(): array
4948
return $return;
5049
}
5150

52-
public function setCurrency(string $iso)
51+
public function setCurrency(null|string $iso)
5352
{
5453
$this->currency = $iso;
5554
return $this;
5655
}
5756

58-
/**
59-
* @param int|float $bal
60-
*/
61-
public function setValue($val)
57+
public function setValue(null|int|float $val)
6258
{
63-
if (!is_numeric($val)) {
64-
throw new GA4Exception("setDiscount value must be numeric");
65-
}
66-
67-
$this->value = 0 + $val;
59+
$this->value = $val;
6860
return $this;
6961
}
7062

71-
public function setCoupon(string $code)
63+
public function setCoupon(null|string $code)
7264
{
7365
$this->coupon = $code;
7466
return $this;
7567
}
7668

77-
public function setPaymentType(string $type)
69+
public function setPaymentType(null|string $type)
7870
{
7971
$this->payment_type = $type;
8072
return $this;
@@ -85,4 +77,9 @@ public function addItem(Item $item)
8577
$this->items[] = $item->toArray();
8678
return $this;
8779
}
80+
81+
public function resetItems()
82+
{
83+
$this->items = [];
84+
}
8885
}

src/Event/AddShippingInfo.php

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
namespace AlexWestergaard\PhpGa4\Event;
44

5-
use AlexWestergaard\PhpGa4\GA4Exception;
6-
use AlexWestergaard\PhpGa4\Facade;
7-
use AlexWestergaard\PhpGa4\Model;
85
use AlexWestergaard\PhpGa4\Item;
6+
use AlexWestergaard\PhpGa4\Model;
7+
use AlexWestergaard\PhpGa4\Facade;
98

109
class AddShippingInfo extends Model\Event implements Facade\AddShippingInfo
1110
{
12-
protected $currency;
13-
protected $value;
14-
protected $coupon;
15-
protected $shipping_tier;
16-
protected $items = [];
11+
protected null|string $currency;
12+
protected null|int|float $value;
13+
protected null|string $coupon;
14+
protected null|string $shipping_tier;
15+
protected array $items = [];
1716

1817
public function getName(): string
1918
{
@@ -49,32 +48,25 @@ public function getRequiredParams(): array
4948
return $return;
5049
}
5150

52-
public function setCurrency(string $iso)
51+
public function setCurrency(null|string $iso)
5352
{
5453
$this->currency = $iso;
5554
return $this;
5655
}
5756

58-
/**
59-
* @param int|float $val
60-
*/
61-
public function setValue($val)
57+
public function setValue(null|int|float $val)
6258
{
63-
if (!is_numeric($val)) {
64-
throw new GA4Exception("setValue value must be numeric");
65-
}
66-
67-
$this->value = 0 + $val;
59+
$this->value = $val;
6860
return $this;
6961
}
7062

71-
public function setCoupon(string $code)
63+
public function setCoupon(null|string $code)
7264
{
7365
$this->coupon = $code;
7466
return $this;
7567
}
7668

77-
public function setShippingTier(string $tier)
69+
public function setShippingTier(null|string $tier)
7870
{
7971
$this->shipping_tier = $tier;
8072
return $this;
@@ -85,4 +77,9 @@ public function addItem(Item $item)
8577
$this->items[] = $item->toArray();
8678
return $this;
8779
}
80+
81+
public function resetItems()
82+
{
83+
$this->items = [];
84+
}
8885
}

src/Event/AddToCart.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22

33
namespace AlexWestergaard\PhpGa4\Event;
44

5-
use AlexWestergaard\PhpGa4\GA4Exception;
6-
use AlexWestergaard\PhpGa4\Facade;
7-
use AlexWestergaard\PhpGa4\Model;
85
use AlexWestergaard\PhpGa4\Item;
6+
use AlexWestergaard\PhpGa4\Model;
7+
use AlexWestergaard\PhpGa4\Facade;
98

109
class AddToCart extends Model\Event implements Facade\AddToCart
1110
{
12-
protected $currency;
13-
protected $value;
14-
protected $items = [];
11+
protected null|string $currency;
12+
protected null|int|float $value;
13+
protected array $items = [];
1514

1615
public function getName(): string
1716
{
@@ -45,22 +44,15 @@ public function getRequiredParams(): array
4544
return $return;
4645
}
4746

48-
public function setCurrency(string $iso)
47+
public function setCurrency(null|string $iso)
4948
{
5049
$this->currency = $iso;
5150
return $this;
5251
}
5352

54-
/**
55-
* @param int|float $val
56-
*/
57-
public function setValue($val)
53+
public function setValue(null|int|float $val)
5854
{
59-
if (!is_numeric($val)) {
60-
throw new GA4Exception("setValue value must be numeric");
61-
}
62-
63-
$this->value = 0 + $val;
55+
$this->value = $val;
6456
return $this;
6557
}
6658

@@ -69,4 +61,9 @@ public function addItem(Item $item)
6961
$this->items[] = $item->toArray();
7062
return $this;
7163
}
64+
65+
public function resetItems()
66+
{
67+
$this->items = [];
68+
}
7269
}

0 commit comments

Comments
 (0)