Skip to content

Commit

Permalink
Merge pull request #71 from adshares/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
m-pilarczyk authored Jun 1, 2023
2 parents ffb09a5 + 1d70ad7 commit ffcf480
Show file tree
Hide file tree
Showing 28 changed files with 326 additions and 98 deletions.
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.5.0] - 2022-01-25
## [1.6.0] - 2023-05-30
### Added
- Reject events without valid ads.txt

## [1.5.0] - 2023-01-25
### Added
- Fetch reports
### Changed
Expand Down Expand Up @@ -92,7 +96,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Rewriting from Python to PHP


[Unreleased]: https://github.com/adshares/adpay/compare/v1.2.0...HEAD
[Unreleased]: https://github.com/adshares/adpay/compare/v1.6.0...HEAD
[1.6.0]: https://github.com/adshares/adpay/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/adshares/adpay/compare/v1.4.2...v1.5.0
[1.4.2]: https://github.com/adshares/adpay/compare/v1.4.1...v1.4.2
[1.4.1]: https://github.com/adshares/adpay/compare/v1.4.0...v1.4.1
Expand Down
21 changes: 11 additions & 10 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ sonar.host.url=https://sonarcloud.io
sonar.organization=adshares-github
sonar.projectKey=adshares-adpay
sonar.projectName=Adshares AdPay
sonar.projectVersion=1.5
sonar.projectVersion=1.6
sonar.projectVersion=1.6

# =====================================================
# Meta-data for the project
Expand Down
1 change: 1 addition & 0 deletions src/Application/DTO/EventUpdateDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ protected function createImpressionModel(array $input): Impression
$context = new Context(
$input['human_score'],
$input['page_rank'],
$input['ads_txt'] ?? null,
$input['keywords'] ?? [],
$input['context'] ?? []
);
Expand Down
17 changes: 9 additions & 8 deletions src/Domain/Model/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@

abstract class Event
{
/** @var Id */
private $id;
private Id $id;

/** @var EventType */
private $type;
private EventType $type;

/** @var DateTimeInterface */
private $time;
private DateTimeInterface $time;

/** @var ImpressionCase */
private $case;
private ImpressionCase $case;

public function __construct(
Id $id,
Expand Down Expand Up @@ -143,4 +139,9 @@ public function getPageRank(): float
{
return $this->case->getPageRank();
}

public function getAdsTxt(): ?int
{
return $this->case->getAdsTxt();
}
}
17 changes: 9 additions & 8 deletions src/Domain/Model/Impression.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@

final class Impression
{
/** @var Id */
private $id;
private Id $id;

/** @var Id */
private $trackingId;
private Id $trackingId;

/** @var Id */
private $userId;
private Id $userId;

/** @var Context */
private $context;
private Context $context;

public function __construct(
Id $id,
Expand Down Expand Up @@ -72,4 +68,9 @@ public function getPageRank(): float
{
return $this->context->getPageRank();
}

public function getAdsTxt(): ?int
{
return $this->context->getAdsTxt();
}
}
29 changes: 13 additions & 16 deletions src/Domain/Model/ImpressionCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,21 @@

final class ImpressionCase
{
/** @var Id */
private $id;
private Id $id;

/** @var DateTimeInterface */
private $time;
private DateTimeInterface $time;

/** @var Id */
private $publisherId;
private Id $publisherId;

/** @var ?Id */
private $zoneId;
private ?Id $zoneId;

/** @var Id */
private $advertiserId;
private Id $advertiserId;

/** @var Id */
private $campaignId;
private Id $campaignId;

/** @var Id */
private $bannerId;
private Id $bannerId;

/** @var Impression */
private $impression;
private Impression $impression;

public function __construct(
Id $id,
Expand Down Expand Up @@ -133,4 +125,9 @@ public function getPageRank(): float
{
return $this->impression->getPageRank();
}

public function getAdsTxt(): ?int
{
return $this->impression->getAdsTxt();
}
}
21 changes: 7 additions & 14 deletions src/Domain/Model/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,15 @@

final class Payment
{
/** @var EventType */
private $eventType;
private EventType $eventType;

/** @var Id */
private $eventId;
private Id $eventId;

/** @var PaymentStatus */
private $status;
private PaymentStatus $status;

/** @var ?int */
private $value;
private ?int $value;

/** @var int */
private $reportId;
private ?int $reportId;

public function __construct(
EventType $eventType,
Expand All @@ -37,9 +32,7 @@ public function __construct(
$this->eventId = $eventId;
$this->status = $status;
$this->value = $value;
if ($reportId !== null) {
$this->reportId = $reportId;
}
$this->reportId = $reportId;
}

public function getReportId(): int
Expand Down Expand Up @@ -81,7 +74,7 @@ public function isAccepted(): bool
return $this->status->isAccepted();
}

public function getValue()
public function getValue(): ?int
{
return $this->value;
}
Expand Down
2 changes: 2 additions & 0 deletions src/Domain/Service/PaymentCalculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ private function validateEvent(array $event): int

if (null === $campaign) {
return PaymentStatus::CAMPAIGN_NOT_FOUND;
} elseif (0 === $event['ads_txt']) {
return PaymentStatus::INVALID_ADS_TXT;
}

$caseTime = DateTimeHelper::fromString($event['case_time']);
Expand Down
36 changes: 26 additions & 10 deletions src/Domain/ValueObject/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@

class Context
{
/** @var float */
private $humanScore;
private float $humanScore;

/** @var float */
private $pageRank;
private float $pageRank;

/** @var array */
private $keywords;
private ?int $adsTxt;

/* @var array */
private $data;
private array $keywords;

public function __construct(float $humanScore, float $pageRank, array $keywords = [], array $data = [])
{
private array $data;

public function __construct(
float $humanScore,
float $pageRank,
?int $adsTxt = null,
array $keywords = [],
array $data = [],
) {
if ($humanScore < 0 || $humanScore > 1) {
throw InvalidArgumentException::fromArgument(
'human score',
Expand All @@ -36,9 +39,17 @@ public function __construct(float $humanScore, float $pageRank, array $keywords
'Must be in the range of <0, 1> or equal -1.'
);
}
if (null !== $adsTxt && 0 !== $adsTxt && 1 !== $adsTxt) {
throw InvalidArgumentException::fromArgument(
'ads txt',
(string)$adsTxt,
'Must be 0, 1 or null.'
);
}

$this->humanScore = $humanScore;
$this->pageRank = $pageRank;
$this->adsTxt = $adsTxt;
$this->keywords = $keywords;
$this->data = $data;
}
Expand All @@ -53,6 +64,11 @@ public function getPageRank(): float
return $this->pageRank;
}

public function getAdsTxt(): ?int
{
return $this->adsTxt;
}

public function getKeywords(): array
{
return $this->keywords;
Expand Down
3 changes: 1 addition & 2 deletions src/Domain/ValueObject/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

class Id
{
/** @var string */
private $id;
private string $id;

public function __construct(string $id)
{
Expand Down
6 changes: 4 additions & 2 deletions src/Domain/ValueObject/PaymentStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ final class PaymentStatus

public const CONVERSION_NOT_FOUND = 6;

public const INVALID_ADS_TXT = 7;

private static $labels = [
self::ACCEPTED => 'accepted',
self::CAMPAIGN_NOT_FOUND => 'rejected:campaign_not_found',
Expand All @@ -30,10 +32,10 @@ final class PaymentStatus
self::BANNER_NOT_FOUND => 'rejected:banner_not_found',
self::CAMPAIGN_OUTDATED => 'rejected:campaign_outdated',
self::CONVERSION_NOT_FOUND => 'rejected:conversion_not_found',
self::INVALID_ADS_TXT => 'rejected:invalid_ads_txt',
];

/** @var ?int */
private $status;
private ?int $status;

public function __construct(?int $status = null)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Infrastructure/Mapper/EventMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static function map(Event $event): array
'user_id' => $event->getUserId()->toBin(),
'human_score' => $event->getHumanScore(),
'page_rank' => $event->getPageRank(),
'ads_txt' => $event->getAdsTxt(),
'keywords' => $event->getKeywords(),
'context' => $event->getContextData(),
];
Expand All @@ -52,6 +53,7 @@ public static function types(): array
'user_id' => Types::BINARY,
'human_score' => Types::FLOAT,
'page_rank' => Types::FLOAT,
'ads_txt' => Types::INTEGER,
'keywords' => Types::JSON,
'context' => Types::JSON,
];
Expand All @@ -75,6 +77,7 @@ public static function fillRaw(array $row): array
'user_id' => bin2hex($row['user_id']),
'human_score' => (float)$row['human_score'],
'page_rank' => (float)$row['page_rank'],
'ads_txt' => $row['ads_txt'],
'keywords' => json_decode($row['keywords'], true),
'context' => json_decode($row['context'], true),
];
Expand Down
Loading

0 comments on commit ffcf480

Please sign in to comment.