open-orchestra/open-orchestra-cms-bundle

View on GitHub
ApiBundle/Transformer/ContentTransformer.php

Summary

Maintainability
B
4 hrs
Test Coverage

Method transform has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function transform($content, array $params = array())
    {
        if (!$content instanceof ContentInterface) {
            throw new TransformerParameterTypeException();
        }
Severity: Minor
Found in ApiBundle/Transformer/ContentTransformer.php - About 1 hr to fix

Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        $facadeClass,
        StatusRepositoryInterface $statusRepository,
        ContentRepositoryInterface $contentRepository,
        AuthorizationCheckerInterface $authorizationChecker,
        ContextBackOfficeInterface $contextManager,
Severity: Minor
Found in ApiBundle/Transformer/ContentTransformer.php - About 45 mins to fix

The class ContentTransformer has a coupling between objects value of 14. Consider to reduce the number of dependencies under 13.
Open

class ContentTransformer extends AbstractSecurityCheckerAwareTransformer
{
    protected $statusRepository;
    protected $contentRepository;
    protected $contextManager;

CouplingBetweenObjects

Since: 1.1.0

A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

Example

class Foo {
    /**
     * @var \foo\bar\X
     */
    private $x = null;

    /**
     * @var \foo\bar\Y
     */
    private $y = null;

    /**
     * @var \foo\bar\Z
     */
    private $z = null;

    public function setFoo(\Foo $foo) {}
    public function setBar(\Bar $bar) {}
    public function setBaz(\Baz $baz) {}

    /**
     * @return \SplObjectStorage
     * @throws \OutOfRangeException
     * @throws \InvalidArgumentException
     * @throws \ErrorException
     */
    public function process(\Iterator $it) {}

    // ...
}

Source https://phpmd.org/rules/design.html#couplingbetweenobjects

Avoid unused parameters such as '$params'.
Open

    public function transform($content, array $params = array())

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Parameter $content has undeclared type \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

    public function transform($content, array $params = array())

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        if (!$content instanceof ContentInterface) {

Parameter $authorizationChecker has undeclared type \Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface
Open

    public function __construct(

Call to undeclared method \OpenOrchestra\ApiBundle\Transformer\ContentTransformer::getContext
Open

        $facade->status = $this->getContext()->transform('status', $content->getStatus());

Call to method getCreatedAt from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->createdAt = $content->getCreatedAt();

Call to method __construct from undeclared class \OpenOrchestra\BaseApi\Exceptions\TransformerParameterTypeException
Open

            throw new TransformerParameterTypeException();

Call to method getAttributes from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        foreach ($content->getAttributes() as $attribute) {

Reference to undeclared property \OpenOrchestra\ApiBundle\Transformer\ContentTransformer->authorizationChecker
Open

            $facade->addRight('can_delete_version', $this->authorizationChecker->isGranted(ContributionActionInterface::DELETE, $content) &&

Reference to instance property status from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            null !== $facade->status &&

Reference to instance property status from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            null !== $facade->status->id &&

Call to method getId from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->id = $content->getId();

Call to method getLanguage from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->language = $content->getLanguage();

Call to method isUsed from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->used = $content->isUsed();

Reference to undeclared property \OpenOrchestra\ApiBundle\Transformer\ContentTransformer->authorizationChecker
Open

            $facade->addRight('can_duplicate', $this->authorizationChecker->isGranted(ContributionActionInterface::CREATE, ContentInterface::ENTITY_TYPE));

Reference to undeclared class \OpenOrchestra\BaseApi\Transformer\AbstractSecurityCheckerAwareTransformer
Open

        parent::__construct($facadeClass, $authorizationChecker);

Call to method findById from undeclared class \OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface
Open

            return $this->contentRepository->findById($facade->id);

Parameter $statusRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\StatusRepositoryInterface
Open

    public function __construct(

Call to method find from undeclared class \OpenOrchestra\ModelInterface\Repository\StatusRepositoryInterface
Open

            $status = $this->statusRepository->find($facade->status->id);

Parameter $contentRepository has undeclared type \OpenOrchestra\ModelInterface\Repository\ContentRepositoryInterface
Open

    public function __construct(

Call to method getContentType from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->contentType = $content->getContentType();

Call to undeclared method \OpenOrchestra\ApiBundle\Transformer\ContentTransformer::newFacade
Open

        $facade = $this->newFacade();

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

            $params['source'] instanceof ContentInterface &&

Call to method getStatus from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->statusLabel = $content->getStatus()->getLabel($this->contextManager->getBackOfficeLanguage());

Reference to undeclared property \OpenOrchestra\ApiBundle\Transformer\ContentTransformer->authorizationChecker
Open

            $facade->addRight('can_edit', $this->authorizationChecker->isGranted(ContributionActionInterface::EDIT, $content));

Reference to instance property status from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            $status = $this->statusRepository->find($facade->status->id);

Reference to instance property id from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

        if (null !== $facade->id) {

Call to method getContentId from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->contentId = $content->getContentId();

Call to method getVersion from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->version = $content->getVersion();

Call to method getVersionName from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->versionName = $content->getVersionName();

@throws annotation of reverseTransform has suspicious class type \OpenOrchestra\ApiBundle\Exceptions\HttpException\StatusChangeNotGrantedHttpException, which does not extend Error/Exception
Open

    public function reverseTransform(FacadeInterface $facade, array $params = array())

Class extends undeclared class \OpenOrchestra\BaseApi\Transformer\AbstractSecurityCheckerAwareTransformer
Open

class ContentTransformer extends AbstractSecurityCheckerAwareTransformer

Call to method isDeleted from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->deleted = $content->isDeleted();

Checking instanceof against undeclared class \OpenOrchestra\ModelInterface\Model\StatusInterface
Open

            if ($status instanceof StatusInterface) {

Return type of transform() is undeclared type \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

    public function transform($content, array $params = array())

@throws type of transform has undeclared type \OpenOrchestra\BaseApi\Exceptions\TransformerParameterTypeException
Open

    public function transform($content, array $params = array())

Call to method getName from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->name = $content->getName();

Call to method getUpdatedAt from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->updatedAt = $content->getUpdatedAt();

Call to undeclared method \OpenOrchestra\ApiBundle\Transformer\ContentTransformer::hasGroup
Open

        if ($this->hasGroup(CMSGroupContext::AUTHORIZATIONS)) {

Call to method getStatus from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->status = $this->getContext()->transform('status', $content->getStatus());

Call to undeclared method \OpenOrchestra\ApiBundle\Transformer\ContentTransformer::getContext
Open

            $contentAttribute = $this->getContext()->transform('content_attribute', $attribute);

Reference to instance property status from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            $params['source']->getStatus()->getId() !== $facade->status->id

Call to method getCreatedBy from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->createdBy = $content->getCreatedBy();

Call to method isLinkedToSite from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->linkedToSite = $content->isLinkedToSite();

Call to undeclared method \OpenOrchestra\ApiBundle\Transformer\ContentTransformer::hasGroup
Open

        if ($this->hasGroup(CMSGroupContext::AUTHORIZATIONS_DELETE_VERSION)) {

Reference to instance property id from undeclared class \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

            return $this->contentRepository->findById($facade->id);

Reference to undeclared property \OpenOrchestra\ApiBundle\Transformer\ContentTransformer->authorizationChecker
Open

            $facade->addRight('can_delete', $this->authorizationChecker->isGranted(ContributionActionInterface::DELETE, $content) &&

Reference to constant ENTITY_TYPE from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

            $facade->addRight('can_duplicate', $this->authorizationChecker->isGranted(ContributionActionInterface::CREATE, ContentInterface::ENTITY_TYPE));

Call to method getUpdatedBy from undeclared class \OpenOrchestra\ModelInterface\Model\ContentInterface
Open

        $facade->updatedBy = $content->getUpdatedBy();

Parameter $facade has undeclared type \OpenOrchestra\BaseApi\Facade\FacadeInterface
Open

    public function reverseTransform(FacadeInterface $facade, array $params = array())

Identical blocks of code found in 2 locations. Consider refactoring.
Open

        if (array_key_exists('source', $params) &&
            $params['source'] instanceof ContentInterface &&
            null !== $facade->status &&
            null !== $facade->status->id &&
            $params['source']->getStatus()->getId() !== $facade->status->id
Severity: Major
Found in ApiBundle/Transformer/ContentTransformer.php and 1 other location - About 1 hr to fix
ApiBundle/Transformer/NodeTransformer.php on lines 236..246

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 120.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Line exceeds 120 characters; contains 132 characters
Open

            $facade->addRight('can_delete', $this->authorizationChecker->isGranted(ContributionActionInterface::DELETE, $content) &&

Line exceeds 120 characters; contains 127 characters
Open

            $facade->addRight('can_edit', $this->authorizationChecker->isGranted(ContributionActionInterface::EDIT, $content));

Line exceeds 120 characters; contains 140 characters
Open

            $facade->addRight('can_delete_version', $this->authorizationChecker->isGranted(ContributionActionInterface::DELETE, $content) &&

Line exceeds 120 characters; contains 155 characters
Open

            $facade->addRight('can_duplicate', $this->authorizationChecker->isGranted(ContributionActionInterface::CREATE, ContentInterface::ENTITY_TYPE));

Expected 0 spaces before closing bracket; newline found
Open

            $facade->addRight('can_delete_version', $this->authorizationChecker->isGranted(ContributionActionInterface::DELETE, $content) &&

Expected 0 spaces before closing bracket; newline found
Open

            $facade->addRight('can_delete', $this->authorizationChecker->isGranted(ContributionActionInterface::DELETE, $content) &&

There are no issues that match your filters.

Category
Status