Issues (23)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Repositories/Cache/CacheTranslationDecorator.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace Modules\Translation\Repositories\Cache;
2
3
use Modules\Core\Repositories\Cache\BaseCacheDecorator;
4
use Modules\Translation\Entities\TranslationTranslation;
5
use Modules\Translation\Repositories\TranslationRepository;
6
7
class CacheTranslationDecorator extends BaseCacheDecorator implements TranslationRepository
8
{
9
    public function __construct(TranslationRepository $recipe)
10
    {
11
        parent::__construct();
12
        $this->entityName = 'translation.translations';
13
        $this->repository = $recipe;
14
    }
15
16
    /**
17
     * @param string $key
18
     * @param string $locale
19
     * @return string
20
     */
21
    public function findByKeyAndLocale($key, $locale = null)
22
    {
23
        $cleanKey = $this->cleanKey($key);
24
25
        $locale = $locale ?: app()->getLocale();
26
27
        return $this->cache
28
            ->tags($this->entityName, 'global')
0 ignored issues
show
The call to Repository::tags() has too many arguments starting with 'global'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
29
            ->rememberForever("{$this->entityName}.findByKeyAndLocale.{$cleanKey}.{$locale}",
30
                function () use ($key, $locale) {
31
                    return $this->repository->findByKeyAndLocale($key, $locale);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Modules\Core\Repositories\BaseRepository as the method findByKeyAndLocale() does only exist in the following implementations of said interface: Modules\Translation\Repo...cheTranslationDecorator, Modules\Translation\Repo...ntTranslationRepository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
32
                }
33
            );
34
    }
35
36
    public function allFormatted()
37
    {
38
        return $this->cache
39
            ->tags($this->entityName, 'global')
0 ignored issues
show
The call to Repository::tags() has too many arguments starting with 'global'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
40
            ->rememberForever("{$this->locale}.{$this->entityName}.allFormatted",
41
                function () {
42
                    return $this->repository->allFormatted();
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Modules\Core\Repositories\BaseRepository as the method allFormatted() does only exist in the following implementations of said interface: Modules\Translation\Repo...cheTranslationDecorator, Modules\Translation\Repo...ntTranslationRepository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
43
                }
44
            );
45
    }
46
47
    public function saveTranslationForLocaleAndKey($locale, $key, $value)
48
    {
49
        $this->cache->tags($this->entityName)->flush();
50
51
        return $this->repository->saveTranslationForLocaleAndKey($locale, $key, $value);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Modules\Core\Repositories\BaseRepository as the method saveTranslationForLocaleAndKey() does only exist in the following implementations of said interface: Modules\Translation\Repo...cheTranslationDecorator, Modules\Translation\Repo...ntTranslationRepository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
52
    }
53
54
    public function findTranslationByKey($key)
55
    {
56
        $cleanKey = $this->cleanKey($key);
57
58
        return $this->cache
59
            ->tags($this->entityName, 'global')
0 ignored issues
show
The call to Repository::tags() has too many arguments starting with 'global'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
            ->rememberForever("{$this->locale}.{$this->entityName}.findTranslationByKey.{$cleanKey}",
61
                function () use ($key) {
62
                    return $this->repository->findTranslationByKey($key);
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Modules\Core\Repositories\BaseRepository as the method findTranslationByKey() does only exist in the following implementations of said interface: Modules\Translation\Repo...cheTranslationDecorator, Modules\Translation\Repo...ntTranslationRepository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
63
                }
64
            );
65
    }
66
67
    /**
68
     * Update the given translation key with the given data
69
     * @param string $key
70
     * @param array $data
71
     * @return mixed
72
     */
73
    public function updateFromImport($key, array $data)
74
    {
75
        $this->cache->tags($this->entityName)->flush();
76
77
        return $this->repository->updateFromImport($key, $data);
0 ignored issues
show
The method updateFromImport() does not exist on Modules\Core\Repositories\BaseRepository. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
78
    }
79
80
    /**
81
     * Set the given value on the given TranslationTranslation
82
     * @param TranslationTranslation $translationTranslation
83
     * @param string $value
84
     * @return void
85
     */
86
    public function updateTranslationToValue(TranslationTranslation $translationTranslation, $value)
87
    {
88
        $this->cache->tags($this->entityName)->flush();
89
90
        return $this->repository->updateTranslationToValue($translationTranslation, $value);
0 ignored issues
show
The method updateTranslationToValue() does not exist on Modules\Core\Repositories\BaseRepository. Did you maybe mean update()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
91
    }
92
93
    /**
94
     * Clean a Cache Key so it is safe for use
95
     * @param string $key   Potentially unsafe key
96
     * @return string
97
     */
98
    protected function cleanKey($key)
99
    {
100
        return str_replace(" ", "--", $key);
101
    }
102
}
103