Code Duplication    Length = 9-12 lines in 7 locations

src/SWP/Bundle/CoreBundle/EventListener/CanceledPackageListener.php 1 location

@@ 88-99 (lines=12) @@
85
     *
86
     * @return PackageInterface
87
     */
88
    private function getPackage(GenericEvent $event)
89
    {
90
        /** @var PackageInterface $package */
91
        if (!($package = $event->getSubject()) instanceof PackageInterface) {
92
            throw UnexpectedTypeException::unexpectedType(
93
                is_object($package) ? get_class($package) : gettype($package),
94
                PackageInterface::class
95
            );
96
        }
97
98
        return $package;
99
    }
100
}
101

src/SWP/Bundle/CoreBundle/Rule/PublishDestinationResolver.php 2 locations

@@ 71-80 (lines=10) @@
68
        return $this->publishDestinationFactory->createWithTenantAndRoute($tenant, $route);
69
    }
70
71
    private function findTenantByCodeOrThrowException(string $code)
72
    {
73
        if (!($tenant = $this->tenantRepository->findOneByCode($code)) instanceof TenantInterface) {
74
            throw UnexpectedTypeException::unexpectedType(
75
                is_object($tenant) ? get_class($tenant) : gettype($tenant),
76
                TenantInterface::class);
77
        }
78
79
        return $tenant;
80
    }
81
82
    private function findRouteByIdOrThrowException(int $id)
83
    {
@@ 82-91 (lines=10) @@
79
        return $tenant;
80
    }
81
82
    private function findRouteByIdOrThrowException(int $id)
83
    {
84
        if (!($route = $this->routeRepository->findOneBy(['id' => $id])) instanceof RouteInterface) {
85
            throw UnexpectedTypeException::unexpectedType(
86
                is_object($route) ? get_class($route) : gettype($route),
87
                RouteInterface::class);
88
        }
89
90
        return $route;
91
    }
92
}
93

src/SWP/Bundle/MultiTenancyBundle/EventListener/OrganizationSubscriber.php 1 location

@@ 94-102 (lines=9) @@
91
        }
92
    }
93
94
    private function ensureOrganizationExists(OrganizationInterface $organization = null)
95
    {
96
        if (!$organization instanceof OrganizationInterface) {
97
            throw UnexpectedTypeException::unexpectedType(
98
                is_object($organization) ? get_class($organization) : gettype($organization),
99
                OrganizationInterface::class
100
            );
101
        }
102
    }
103
}
104

src/SWP/Bundle/CoreBundle/EventListener/PackageStatusListener.php 1 location

@@ 81-92 (lines=12) @@
78
     *
79
     * @return PackageInterface
80
     */
81
    private function getPackage(ArticleInterface $article)
82
    {
83
        /** @var PackageInterface $package */
84
        if (!($package = $article->getPackage()) instanceof PackageInterface) {
85
            throw UnexpectedTypeException::unexpectedType(
86
                is_object($package) ? get_class($package) : gettype($package),
87
                PackageInterface::class
88
            );
89
        }
90
91
        return $package;
92
    }
93
}
94

src/SWP/Bundle/CoreBundle/EventListener/UpdatedPackageListener.php 1 location

@@ 105-116 (lines=12) @@
102
        $this->eventDispatcher->dispatch(MultiTenancyEvents::TENANTABLE_ENABLE);
103
    }
104
105
    private function getPackage(GenericEvent $event)
106
    {
107
        /** @var PackageInterface $package */
108
        if (!($package = $event->getSubject()) instanceof PackageInterface) {
109
            throw UnexpectedTypeException::unexpectedType(
110
                is_object($package) ? get_class($package) : gettype($package),
111
                PackageInterface::class
112
            );
113
        }
114
115
        return $package;
116
    }
117
}
118

src/SWP/Bundle/CoreBundle/Rule/Applicator/PackageRuleApplicator.php 1 location

@@ 88-97 (lines=10) @@
85
        }
86
    }
87
88
    private function findTenantByCodeOrThrowException(string $code): TenantInterface
89
    {
90
        if (!($tenant = $this->tenantRepository->findOneByCode($code)) instanceof TenantInterface) {
91
            throw UnexpectedTypeException::unexpectedType(
92
                is_object($tenant) ? get_class($tenant) : gettype($tenant),
93
                TenantInterface::class);
94
        }
95
96
        return $tenant;
97
    }
98
99
    /**
100
     * {@inheritdoc}