Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot call abstract method Prooph\Common\Messaging\DomainMessage::setPayload() #23

Closed
paales opened this issue Mar 10, 2018 · 2 comments
Labels
bug Something isn't working

Comments

@paales
Copy link
Contributor

paales commented Mar 10, 2018

It seems the setPayload tries to call an abstract parent::setPayload, should probably be removed.

namespace ReachDigital\Subscription\Model\ProductPlan {
    final class SubmitFormGlobalScope extends \Prooph\Common\Messaging\Command
    {
        use \Prooph\Common\Messaging\PayloadTrait;

        protected $messageName = 'ReachDigital\Subscription\Model\ProductPlan\SubmitFormGlobalScope';

        public function planId(): PlanId
        {
            return PlanId::fromString($this->payload['planId']);
        }

        public function productId(): ProductId
        {
            return ProductId::fromScalar($this->payload['productId']);
        }

        public function enabled(): Enabled
        {
            return Enabled::fromScalar($this->payload['enabled']);
        }

        public function enabledOnFrontend(): EnabledOnFrontend
        {
            return EnabledOnFrontend::fromScalar($this->payload['enabledOnFrontend']);
        }

        public function title(): Title
        {
            return Title::fromString($this->payload['title']);
        }

        public function description(): Description
        {
            return Description::fromString($this->payload['description']);
        }

        public function schedule(): Schedule
        {
            return Schedule::fromArray($this->payload['schedule']);
        }

        public function interval(): Interval
        {
            return Interval::fromArray($this->payload['interval']);
        }

        public function initialPrice(): InitialPrice
        {
            return InitialPrice::fromScalar($this->payload['initialPrice']);
        }

        public function installmentPrice(): InstallmentPrice
        {
            return InstallmentPrice::fromScalar($this->payload['installmentPrice']);
        }

        public static function with(PlanId $planId, ProductId $productId, Enabled $enabled, EnabledOnFrontend $enabledOnFrontend, Title $title, Description $description, Schedule $schedule, Interval $interval, InitialPrice $initialPrice, InstallmentPrice $installmentPrice): SubmitFormGlobalScope
        {
            return new self([
                'planId' => $planId->toString(),
                'productId' => $productId->toScalar(),
                'enabled' => $enabled->toScalar(),
                'enabledOnFrontend' => $enabledOnFrontend->toScalar(),
                'title' => $title->toString(),
                'description' => $description->toString(),
                'schedule' => $schedule->toArray(),
                'interval' => $interval->toArray(),
                'initialPrice' => $initialPrice->toScalar(),
                'installmentPrice' => $installmentPrice->toScalar(),
            ]);
        }

        protected function setPayload(array $payload): void
        {
            if (! isset($payload['planId']) || ! is_string($payload['planId'])) {
                throw new \InvalidArgumentException("Key 'planId' is missing in payload or is not a string");
            }

            if (! isset($payload['productId']) || ! is_int($payload['productId'])) {
                throw new \InvalidArgumentException("Key 'productId' is missing in payload or is not a int");
            }

            if (! isset($payload['enabled']) || ! is_bool($payload['enabled'])) {
                throw new \InvalidArgumentException("Key 'enabled' is missing in payload or is not a bool");
            }

            if (! isset($payload['enabledOnFrontend']) || ! is_bool($payload['enabledOnFrontend'])) {
                throw new \InvalidArgumentException("Key 'enabledOnFrontend' is missing in payload or is not a bool");
            }

            if (! isset($payload['title']) || ! is_string($payload['title'])) {
                throw new \InvalidArgumentException("Key 'title' is missing in payload or is not a string");
            }

            if (! isset($payload['description']) || ! is_string($payload['description'])) {
                throw new \InvalidArgumentException("Key 'description' is missing in payload or is not a string");
            }

            if (! isset($payload['schedule']) || ! is_array($payload['schedule'])) {
                throw new \InvalidArgumentException("Key 'schedule' is missing in payload or is not an array");
            }

            if (! isset($payload['interval']) || ! is_array($payload['interval'])) {
                throw new \InvalidArgumentException("Key 'interval' is missing in payload or is not an array");
            }

            if (! isset($payload['initialPrice']) || ! is_float($payload['initialPrice'])) {
                throw new \InvalidArgumentException("Key 'initialPrice' is missing in payload or is not a float");
            }

            if (! isset($payload['installmentPrice']) || ! is_float($payload['installmentPrice'])) {
                throw new \InvalidArgumentException("Key 'installmentPrice' is missing in payload or is not a float");
            }

            parent::setPayload($payload);
        }
    }
}
@prolic prolic added the bug Something isn't working label Mar 10, 2018
@prolic prolic closed this as completed in c694ae6 Mar 10, 2018
@prolic
Copy link
Owner

prolic commented Mar 10, 2018

fixed in master, thanks for reporting

@paales
Copy link
Contributor Author

paales commented Mar 11, 2018

Thanks! Works

Adirelle pushed a commit to Adirelle/fpp that referenced this issue Jul 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants