Skip to content

Commit

Permalink
updates for PHP 8.3
Browse files Browse the repository at this point in the history
- remove support for PHP versions < 8.1
- use constructor property promotion
- deprecate getters (use properties instead)
- update test matrix for GitHub Actions
- update README
  • Loading branch information
mjaschen committed Dec 5, 2023
1 parent 4de7219 commit a01b132
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 138 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ jobs:
strategy:
matrix:
php-versions:
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"

name: "analytics-campaign-urls build - PHP ${{ matrix.php-versions }}"

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/composer.lock
/vendor
/.phpunit.result.cache
.phpunit.cache
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Marcus Jaschen <mjaschen@gmail.com>
Copyright (c) 2023 Marcus Jaschen <mjaschen@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# Analytics Campaign URLs

This library allows it to easily append campaign parameters (e. g. for Google Analytics or Piwik) to any given URL.
This library allows it to easily append campaign parameters (e.g. for Google
Analytics, Matomo/Piwik or Plausible) to any given URL.

## Requirements

At least PHP 7.0 is required to use this library.
At least PHP 8.1 is required to use this library in the current version.

Version 2.x of this library supports PHP versions 7.0 or higher.

## Installation

Expand Down Expand Up @@ -50,6 +53,5 @@ $campaignUrlMatomo = Url::addAnalyticsCampaignParams('https://example.com/', $ma
- [Google Analytics Campaign URL Builder][ga]
- [Matomo Campaign URL Builder][matomo]


[ga]: https://ga-dev-tools.appspot.com/campaign-url-builder/
[matomo]: https://matomo.org/docs/tracking-campaigns-url-builder/
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
}
],
"require": {
"php": ">=7.0"
"php": "^8.1"
},
"require-dev": {
"ergebnis/composer-normalize": "^2.13",
"phpunit/phpunit": "^8.0",
"squizlabs/php_codesniffer": "^3.5",
"vimeo/psalm": "^4.4"
"ergebnis/composer-normalize": "^2.39",
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^3.7",
"vimeo/psalm": "^5.0",
"rector/rector": "^0.18.12"
},
"autoload": {
"psr-4": {
Expand All @@ -51,5 +52,10 @@
],
"ci:tests": "./vendor/bin/phpunit",
"ci:validate-composer": "composer validate --no-check-all --strict"
},
"config": {
"allow-plugins": {
"ergebnis/composer-normalize": true
}
}
}
16 changes: 6 additions & 10 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="tests/bootstrap.php"
cacheResult="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="tests/bootstrap.php" cacheResult="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
2 changes: 2 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<psalm
errorLevel="1"
resolveFromConfigFile="true"
findUnusedBaselineEntry="true"
findUnusedCode="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
Expand Down
68 changes: 15 additions & 53 deletions src/Parameters/GoogleAnalytics.php
Original file line number Diff line number Diff line change
@@ -1,92 +1,54 @@
<?php

declare(strict_types=1);

namespace MinistryOfWeb\AnalyticsCampaignUrls\Parameters;

class GoogleAnalytics implements ParametersInterface
{
/**
* @var string
*/
private $campaign;

/**
* @var string
*/
private $medium;

/**
* @var string
*/
private $source;

/**
* @var string
*/
private $term;

/**
* @var string
*/
private $content;

/**
* Parameters constructor.
*
* @param string $campaign
* @param string $medium
* @param string $source
* @param string $term
* @param string $content
*/
public function __construct(
string $campaign,
string $medium = '',
string $source = '',
string $term = '',
string $content = ''
public readonly string $campaign,
public readonly string $medium = '',
public readonly string $source = '',
public readonly string $term = '',
public readonly string $content = ''
) {
$this->campaign = $campaign;
$this->medium = $medium;
$this->source = $source;
$this->term = $term;
$this->content = $content;
}

/**
* @return string
* @deprecated use property instead
*/
public function getCampaign(): string
{
return $this->campaign;
}

/**
* @return string
* @deprecated use property instead
*/
public function getMedium(): string
{
return $this->medium;
}

/**
* @return string
* @deprecated use property instead
*/
public function getSource(): string
{
return $this->source;
}

/**
* @return string
* @deprecated use property instead
*/
public function getTerm(): string
{
return $this->term;
}

/**
* @return string
* @deprecated use property instead
*/
public function getContent(): string
{
Expand All @@ -104,19 +66,19 @@ public function toArray(): array
'utm_campaign' => $this->campaign,
];

if (! empty($this->medium)) {
if (!empty($this->medium)) {
$params['utm_medium'] = $this->medium;
}

if (! empty($this->source)) {
if (!empty($this->source)) {
$params['utm_source'] = $this->source;
}

if (! empty($this->term)) {
if (!empty($this->term)) {
$params['utm_term'] = $this->term;
}

if (! empty($this->content)) {
if (!empty($this->content)) {
$params['utm_content'] = $this->content;
}

Expand Down
68 changes: 15 additions & 53 deletions src/Parameters/Matomo.php
Original file line number Diff line number Diff line change
@@ -1,92 +1,54 @@
<?php

declare(strict_types=1);

namespace MinistryOfWeb\AnalyticsCampaignUrls\Parameters;

class Matomo implements ParametersInterface
{
/**
* @var string
*/
private $campaign;

/**
* @var string
*/
private $medium;

/**
* @var string
*/
private $source;

/**
* @var string
*/
private $keyword;

/**
* @var string
*/
private $content;

/**
* Parameters constructor.
*
* @param string $campaign
* @param string $medium
* @param string $source
* @param string $keyword
* @param string $content
*/
public function __construct(
string $campaign,
string $medium = '',
string $source = '',
string $keyword = '',
string $content = ''
public readonly string $campaign,
public readonly string $medium = '',
public readonly string $source = '',
public readonly string $keyword = '',
public readonly string $content = ''
) {
$this->campaign = $campaign;
$this->medium = $medium;
$this->source = $source;
$this->keyword = $keyword;
$this->content = $content;
}

/**
* @return string
* @deprecated use property instead
*/
public function getCampaign(): string
{
return $this->campaign;
}

/**
* @return string
* @deprecated use property instead
*/
public function getMedium(): string
{
return $this->medium;
}

/**
* @return string
* @deprecated use property instead
*/
public function getSource(): string
{
return $this->source;
}

/**
* @return string
* @deprecated use property instead
*/
public function getKeyword(): string
{
return $this->keyword;
}

/**
* @return string
* @deprecated use property instead
*/
public function getContent(): string
{
Expand All @@ -104,19 +66,19 @@ public function toArray(): array
'pk_campaign' => $this->campaign,
];

if (! empty($this->medium)) {
if (!empty($this->medium)) {
$params['pk_medium'] = $this->medium;
}

if (! empty($this->source)) {
if (!empty($this->source)) {
$params['pk_source'] = $this->source;
}

if (! empty($this->keyword)) {
if (!empty($this->keyword)) {
$params['pk_kwd'] = $this->keyword;
}

if (! empty($this->content)) {
if (!empty($this->content)) {
$params['pk_content'] = $this->content;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Parameters/ParametersInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace MinistryOfWeb\AnalyticsCampaignUrls\Parameters;
Expand All @@ -8,8 +9,6 @@ interface ParametersInterface
/**
* Creates the associative array of URL parameters (key = parameter name;
* value = paramater value).
*
* @return array
*/
public function toArray(): array;
}
1 change: 1 addition & 0 deletions src/Parameters/Piwik.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace MinistryOfWeb\AnalyticsCampaignUrls\Parameters;
Expand Down
Loading

0 comments on commit a01b132

Please sign in to comment.