Skip to content

Commit

Permalink
Merge pull request #235 from wmde/remove-freezable-value-object
Browse files Browse the repository at this point in the history
Remove freezable value object
  • Loading branch information
Abban authored Mar 13, 2024
2 parents 972f84e + 57c6a54 commit b91d23a
Show file tree
Hide file tree
Showing 28 changed files with 217 additions and 494 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

"wmde/email-address": "~1.0",
"wmde/euro": "~1.0",
"wmde/freezable-value-object": "~2.0",
"wmde/fun-validators": "~4.0",
"wmde/fundraising-payments": "~7.0"
},
Expand Down
23 changes: 11 additions & 12 deletions src/DataAccess/DoctrineCommentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Exception\ORMException;
use WMDE\Fundraising\DonationContext\DataAccess\DoctrineEntities\Donation;
use WMDE\Fundraising\DonationContext\Domain\ReadModel\Comment;
use WMDE\Fundraising\DonationContext\Domain\Repositories\CommentFinder;
use WMDE\Fundraising\DonationContext\Domain\Repositories\CommentListingException;
use WMDE\Fundraising\DonationContext\Domain\Repositories\CommentWithAmount;

/**
* @todo Use database tables and arrays instead of ORM to avoid deprecated getAmount
Expand All @@ -24,24 +24,23 @@ public function __construct( EntityManager $entityManager ) {
}

/**
* @see CommentFinder::getPublicComments
*
* @param int $limit
* @param int $offset
*
* @return CommentWithAmount[]
* @return Comment[]
* @see CommentFinder::getPublicComments
*
*/
public function getPublicComments( int $limit, int $offset = 0 ): array {
return array_map(
static function ( Donation $donation ) {
return CommentWithAmount::newInstance()
->setAuthorName( $donation->getPublicRecord() )
->setCommentText( $donation->getComment() )
->setDonationAmount( (float)$donation->getAmount() )
->setDonationTime( $donation->getCreationTime() )
->setDonationId( $donation->getId() ?? 0 )
->freeze()
->assertNoNullFields();
return new Comment(
authorName: $donation->getPublicRecord(),
donationAmount: (float)$donation->getAmount(),
commentText: $donation->getComment(),
donationTime: $donation->getCreationTime(),
donationId: $donation->getId() ?? 0
);
},
$this->getDonations( $limit, $offset )
);
Expand Down
10 changes: 3 additions & 7 deletions src/DataAccess/LegacyConverters/DomainToLegacyConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,9 @@ private function getDataMap( Donation $donation, LegacyPaymentData $legacyPaymen
*/
private function getDataFieldsFromTrackingInfo( DonationTrackingInfo $trackingInfo ): array {
return [
'layout' => $trackingInfo->getLayout(),
'impCount' => $trackingInfo->getTotalImpressionCount(),
'bImpCount' => $trackingInfo->getSingleBannerImpressionCount(),
'tracking' => $trackingInfo->getTracking(),
'skin' => $trackingInfo->getSkin(),
'color' => $trackingInfo->getColor(),
'source' => $trackingInfo->getSource(),
'impCount' => $trackingInfo->totalImpressionCount,
'bImpCount' => $trackingInfo->singleBannerImpressionCount,
'tracking' => $trackingInfo->tracking,
];
}
}
12 changes: 5 additions & 7 deletions src/DataAccess/LegacyConverters/LegacyToDomainConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,11 @@ private function assignCancellationAndModeration( DoctrineDonation $dd, Donation
private function createTrackingInfo( DoctrineDonation $dd ): DonationTrackingInfo {
$data = $dd->getDecodedData();

$trackingInfo = DonationTrackingInfo::newBlankTrackingInfo();

$trackingInfo->setTotalImpressionCount( intval( $data['impCount'] ?? '0' ) );
$trackingInfo->setSingleBannerImpressionCount( intval( $data['bImpCount'] ?? '0' ) );
$trackingInfo->setTracking( $data['tracking'] ?? '' );

return $trackingInfo->freeze()->assertNoNullFields();
return new DonationTrackingInfo(
tracking: $data['tracking'] ?? '',
totalImpressionCount: intval( $data['impCount'] ?? '0' ),
singleBannerImpressionCount: intval( $data['bImpCount'] ?? '0' )
);
}

private function createComment( DoctrineDonation $dd ): ?DonationComment {
Expand Down
126 changes: 6 additions & 120 deletions src/Domain/Model/DonationTrackingInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,131 +4,17 @@

namespace WMDE\Fundraising\DonationContext\Domain\Model;

use WMDE\FreezableValueObject\FreezableValueObject;

/**
* TODO: move to Infrastructure
*
* @license GPL-2.0-or-later
* @author Kai Nissen < [email protected] >
* @author Jeroen De Dauw < [email protected] >
*/
class DonationTrackingInfo {
use FreezableValueObject;

private string $tracking;
private string $source = '';
private int $totalImpressionCount;
private int $singleBannerImpressionCount;
private string $color = '';
private string $skin = '';
private string $layout = '';

private function __construct() {
}

public function getTracking(): string {
return $this->tracking;
}

public function setTracking( string $tracking ): void {
$this->assertIsWritable();
$this->tracking = $tracking;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @return string
*/
public function getSource(): string {
return $this->source;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @param string $source
*/
public function setSource( string $source ): void {
$this->assertIsWritable();
$this->source = $source;
}

public function getTotalImpressionCount(): int {
return $this->totalImpressionCount;
}

public function setTotalImpressionCount( int $totalImpressionCount ): void {
$this->assertIsWritable();
$this->totalImpressionCount = $totalImpressionCount;
}

public function getSingleBannerImpressionCount(): int {
return $this->singleBannerImpressionCount;
}

public function setSingleBannerImpressionCount( int $singleBannerImpressionCount ): void {
$this->assertIsWritable();
$this->singleBannerImpressionCount = $singleBannerImpressionCount;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @return string
*/
public function getColor(): string {
return $this->color;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @param string $color
*/
public function setColor( string $color ): void {
$this->assertIsWritable();
$this->color = $color;
}

public function getSkin(): string {
return $this->skin;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @param string $skin
*/
public function setSkin( string $skin ): void {
$this->assertIsWritable();
$this->skin = $skin;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @return string
*/
public function getLayout(): string {
return $this->layout;
}

/**
* @deprecated See https://phabricator.wikimedia.org/T134327
* @param string $layout
*/
public function setLayout( string $layout ): void {
$this->assertIsWritable();
$this->layout = $layout;
public function __construct(
public readonly string $tracking = '',
public readonly int $totalImpressionCount = 0,
public readonly int $singleBannerImpressionCount = 0,
) {
}

public static function newBlankTrackingInfo(): self {
$trackingInfo = new self();
$trackingInfo->setColor( '' );
$trackingInfo->setLayout( '' );
$trackingInfo->setSingleBannerImpressionCount( 0 );
$trackingInfo->setSkin( '' );
$trackingInfo->setSource( '' );
$trackingInfo->setTotalImpressionCount( 0 );
$trackingInfo->setTracking( '' );

return $trackingInfo;
return new self();
}

}
18 changes: 18 additions & 0 deletions src/Domain/ReadModel/Comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare( strict_types = 1 );

namespace WMDE\Fundraising\DonationContext\Domain\ReadModel;

use DateTime;

class Comment {
public function __construct(
public readonly string $authorName,
public readonly float $donationAmount,
public readonly string $commentText,
public readonly DateTime $donationTime,
public readonly int $donationId
) {
}
}
4 changes: 3 additions & 1 deletion src/Domain/Repositories/CommentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace WMDE\Fundraising\DonationContext\Domain\Repositories;

use WMDE\Fundraising\DonationContext\Domain\ReadModel\Comment;

/**
* @license GPL-2.0-or-later
* @author Jeroen De Dauw < [email protected] >
Expand All @@ -16,7 +18,7 @@ interface CommentFinder {
* @param int $limit
* @param int $offset
*
* @return CommentWithAmount[]
* @return Comment[]
*/
public function getPublicComments( int $limit, int $offset = 0 ): array;

Expand Down
76 changes: 0 additions & 76 deletions src/Domain/Repositories/CommentWithAmount.php

This file was deleted.

8 changes: 4 additions & 4 deletions src/Infrastructure/LoggingCommentFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use WMDE\Fundraising\DonationContext\Domain\ReadModel\Comment;
use WMDE\Fundraising\DonationContext\Domain\Repositories\CommentFinder;
use WMDE\Fundraising\DonationContext\Domain\Repositories\CommentListingException;
use WMDE\Fundraising\DonationContext\Domain\Repositories\CommentWithAmount;

/**
* @license GPL-2.0-or-later
Expand All @@ -28,13 +28,13 @@ public function __construct(
}

/**
* @see CommentFinder::getPublicComments
*
* @param int $limit
* @param int $offset
*
* @return CommentWithAmount[]
* @return Comment[]
* @throws CommentListingException
* @see CommentFinder::getPublicComments
*
*/
public function getPublicComments( int $limit, int $offset = 0 ): array {
try {
Expand Down
Loading

0 comments on commit b91d23a

Please sign in to comment.