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

Add phpstan to travis ci #70

Merged
merged 4 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,27 @@ cache:
matrix:
include:
- php: 5.5
# env:
# - COMPOSER_FLAGS="--prefer-lowest --prefer-dist --no-interaction"
env:
- COMPOSER_FLAGS="--prefer-dist --no-interaction" # --prefer-lowest not possible in sulu 1.3
- php: 7.0
env:
# - COMPOSER_FLAGS="--prefer-dist --no-interaction"
- COMPOSER_FLAGS="--prefer-dist --no-interaction"
- CODE_COVERAGE=true
- PHPSTAN=true

before_install:
- phpenv config-add Tests/travis.php.ini
- composer self-update

install:
- travis_retry composer update $COMPOSER_FLAGS
- if [[ $PHPSTAN == 'true' ]]; then travis_retry composer require --dev phpstan/phpstan $COMPOSER_FLAGS ; else travis_retry composer update $COMPOSER_FLAGS ; fi
- composer info -i
- ./Tests/app/console doctrine:database:create
- ./Tests/app/console doctrine:schema:update --force

script:
- ./vendor/bin/phpunit --coverage-clover=coverage.clover
- if [[ $PHPSTAN == 'true' ]]; then ./vendor/bin/phpstan analyse ./ --level 4 -c phpstan.neon ; fi

after_script:
- if [[ $CODE_COVERAGE == 'true' ]]; then wget https://scrutinizer-ci.com/ocular.phar ; fi
Expand Down
5 changes: 4 additions & 1 deletion Controller/ConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Sulu\Bundle\CommunityBundle\Controller;

use Sulu\Bundle\CommunityBundle\DependencyInjection\Configuration;
use Sulu\Bundle\SecurityBundle\Entity\User;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand All @@ -37,7 +38,9 @@ public function indexAction(Request $request, $token)
$success = false;

// Confirm user by token
if ($user = $communityManager->confirm($token)) {
$user = $communityManager->confirm($token);

if ($user instanceof User) {
// Save User
$this->saveEntities();

Expand Down
4 changes: 2 additions & 2 deletions Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,13 @@ public function indexAction(Request $request)
* @param User $user
* @param string $locale
*
* @return Media
* @return Media|null
*/
protected function saveAvatar(Form $form, User $user, $locale)
{
$uploadedFile = $form->get('contact')->get('avatar')->getData();
if (null === $uploadedFile) {
return;
return null;
}

$systemCollectionManager = $this->get('sulu_media.system_collections.manager');
Expand Down
12 changes: 6 additions & 6 deletions Entity/BlacklistItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class BlacklistItem
private $id;

/**
* @var string
* @var string|null
*/
private $pattern;

/**
* @var string
* @var string|null
*/
private $regexp;

/**
* @var string
* @var string|null
*/
private $type;

Expand Down Expand Up @@ -70,7 +70,7 @@ public function getId()
/**
* Get pattern.
*
* @return string
* @return string|null
*/
public function getPattern()
{
Expand All @@ -95,7 +95,7 @@ public function setPattern($pattern)
/**
* Get regexp.
*
* @return string
* @return string|null
*/
public function getRegexp()
{
Expand All @@ -105,7 +105,7 @@ public function getRegexp()
/**
* Get type.
*
* @return string
* @return string|null
*/
public function getType()
{
Expand Down
4 changes: 2 additions & 2 deletions Entity/BlacklistUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class BlacklistUser
private $id;

/**
* @var string
* @var string|null
*/
private $token;

Expand Down Expand Up @@ -74,7 +74,7 @@ public function getId()
/**
* Returns token.
*
* @return string
* @return string|null
*/
public function getToken()
{
Expand Down
6 changes: 3 additions & 3 deletions Entity/BlacklistUserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ class BlacklistUserRepository extends EntityRepository
*
* @param string $token
*
* @return BlacklistUser
* @return BlacklistUser|null
*/
public function findByToken($token)
{
try {
return $this->findOneBy(['token' => $token]);
} catch (NonUniqueResultException $e) {
return;
return null;
} catch (NoResultException $e) {
return;
return null;
}
}
}
12 changes: 6 additions & 6 deletions Entity/EmailConfirmationTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ class EmailConfirmationTokenRepository extends EntityRepository
*
* @param string $token
*
* @return EmailConfirmationToken
* @return EmailConfirmationToken|null
*/
public function findByToken($token)
{
try {
return $this->findOneBy(['token' => $token]);
} catch (NonUniqueResultException $e) {
return;
return null;
} catch (NoResultException $e) {
return;
return null;
}
}

Expand All @@ -44,16 +44,16 @@ public function findByToken($token)
*
* @param UserInterface $user
*
* @return EmailConfirmationToken
* @return EmailConfirmationToken|null
*/
public function findByUser($user)
{
try {
return $this->findOneBy(['user' => $user]);
} catch (NonUniqueResultException $e) {
return;
return null;
} catch (NoResultException $e) {
return;
return null;
}
}
}
4 changes: 2 additions & 2 deletions EventListener/BlacklistListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ public function validateEmail(CommunityEvent $event)
*
* @param string $email
*
* @return string
* @return string|null
*/
private function getType($email)
{
$items = $this->blacklistItemRepository->findBySender($email);

if (0 === count($items)) {
return;
return null;
}

foreach ($items as $item) {
Expand Down
9 changes: 7 additions & 2 deletions EventListener/CompletionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;

/**
* Validates the current user entity.
Expand Down Expand Up @@ -93,6 +94,10 @@ public function onRequest(GetResponseEvent $event)

$token = $this->tokenStorage->getToken();

if (!$token instanceof TokenInterface) {
return;
}

/** @var User $user */
$user = $token->getUser();

Expand Down Expand Up @@ -131,12 +136,12 @@ public function addValidator(CompletionInterface $validator, $webspaceKey)
/**
* @param string $webspaceKey
*
* @return CompletionInterface
* @return CompletionInterface|null
*/
protected function getValidator($webspaceKey)
{
if (!isset($this->validators[$webspaceKey])) {
return;
return null;
}

return $this->validators[$webspaceKey];
Expand Down
6 changes: 6 additions & 0 deletions EventListener/EmailConfirmationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Sulu\Bundle\CommunityBundle\Event\CommunityEvent;
use Sulu\Bundle\CommunityBundle\Mail\Mail;
use Sulu\Bundle\CommunityBundle\Mail\MailFactoryInterface;
use Sulu\Bundle\SecurityBundle\Entity\User;
use Sulu\Bundle\SecurityBundle\Util\TokenGeneratorInterface;

/**
Expand Down Expand Up @@ -72,6 +73,11 @@ public function __construct(
public function sendConfirmationOnEmailChange(CommunityEvent $event)
{
$user = $event->getUser();

if (!$user instanceof User) {
throw new \RuntimeException('Community bundle user need to be instance uf Sulu User');
}

if ($user->getEmail() === $user->getContact()->getMainEmail()) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions Manager/CommunityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function completion(User $user)
public function login(User $user, Request $request)
{
if (!$user->getEnabled()) {
return;
return null;
}

$token = new UsernamePasswordToken(
Expand All @@ -187,7 +187,7 @@ public function confirm($token)
$user = $this->userManager->findByConfirmationKey($token);

if (!$user) {
return;
return null;
}

// Remove Confirmation Key
Expand All @@ -209,7 +209,7 @@ public function passwordForget($emailUsername)
$user = $this->userManager->findUser($emailUsername);

if (!$user) {
return;
return null;
}

$user->setPasswordResetToken($this->userManager->getUniqueToken('passwordResetToken'));
Expand Down
10 changes: 5 additions & 5 deletions Manager/CommunityManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function completion(User $user);
* @param User $user
* @param Request $request
*
* @return UsernamePasswordToken
* @return UsernamePasswordToken|null
*/
public function login(User $user, Request $request);

Expand All @@ -61,7 +61,7 @@ public function login(User $user, Request $request);
*
* @param string $token
*
* @return User
* @return User|null
*/
public function confirm($token);

Expand All @@ -70,14 +70,14 @@ public function confirm($token);
*
* @param string $emailUsername
*
* @return User
* @return User|null
*/
public function passwordForget($emailUsername);

/**
* Reset user password token.
*
* @param User $user
* @param User $user|null
*
* @return User
*/
Expand Down Expand Up @@ -107,7 +107,7 @@ public function getConfigProperty($property);
* @param string $type
* @param string $property
*
* @return string
* @return mixed
*
* @throws \Exception
*/
Expand Down
Loading