Skip to content

Commit

Permalink
almost done with psalm fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
  • Loading branch information
julien-nc committed Mar 17, 2024
1 parent 21963af commit fc1ed7f
Show file tree
Hide file tree
Showing 22 changed files with 1,798 additions and 1,188 deletions.
14 changes: 6 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
extensions: mbstring, intl, sqlite3, curl, xml, json, zip, gd
ini-values: post_max_size=256M, max_execution_time=180
coverage: xdebug
tools: php-cs-fixer, phpunit
tools: php-cs-fixer

- uses: actions/checkout@v2

Expand All @@ -86,21 +86,19 @@ jobs:
fi
echo "php ~/html/nextcloud/occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin"
php ~/html/nextcloud/occ maintenance:install --verbose --database=${{ matrix.databases }} --database-name=nextcloud --database-host=127.0.0.1 --database-port=$DB_PORT --database-user=root --database-pass=rootpassword --admin-user admin --admin-pass admin
cd ~/html/nextcloud/apps/${{ env.APP_ID }}
make composer
php ~/html/nextcloud/occ app:enable --force ${{ env.APP_ID }}
php ~/html/nextcloud/occ maintenance:mode --off
cd ~/html/nextcloud/apps/${{ env.APP_ID }}
curl --location --output ./phpunit https://phar.phpunit.de/phpunit-9.5.phar
chmod +x ./phpunit
echo "##### App is installed"
echo "##### App is installed and enabled"
- name: Perform PhpUnit tests with coverage
if: ${{ matrix.databases == 'sqlite' && matrix.php-versions == '8.1' && matrix.server-versions == 'master' }}
run: |
#php ~/html/nextcloud/occ app:check-code ${{ env.APP_ID }}
mkdir /tmp/coverage
cd /tmp
echo "##### PHPunit"
XDEBUG_MODE=coverage ~/html/nextcloud/apps/${{ env.APP_ID }}/phpunit --configuration ~/html/nextcloud/apps/${{ env.APP_ID }}/phpunit.xml --coverage-text --color=never --coverage-html coverage > /tmp/cov.txt && SUCCESS=yes || SUCCESS=no
XDEBUG_MODE=coverage ~/html/nextcloud/apps/${{ env.APP_ID }}/vendor/bin/phpunit --configuration ~/html/nextcloud/apps/${{ env.APP_ID }}/tests/phpunit.xml --coverage-text --color=never --coverage-html coverage > /tmp/cov.txt && SUCCESS=yes || SUCCESS=no
echo "phpunit finished ############################"
cat /tmp/cov.txt
if [ $SUCCESS = "yes" ]; then echo "TESTS PASSED"; else echo "TESTS FAILED"; exit 1; fi
Expand All @@ -115,7 +113,7 @@ jobs:
- name: Perform PhpUnit tests
if: ${{ !(matrix.databases == 'sqlite' && matrix.php-versions == '8.1' && matrix.server-versions == 'master') }}
run: |
~/html/nextcloud/apps/${{ env.APP_ID }}/phpunit --configuration ~/html/nextcloud/apps/${{ env.APP_ID }}/phpunit.xml && SUCCESS=yes || SUCCESS=no
~/html/nextcloud/apps/${{ env.APP_ID }}/vendor/bin/phpunit --configuration ~/html/nextcloud/apps/${{ env.APP_ID }}/tests/phpunit.xml && SUCCESS=yes || SUCCESS=no
if [ $SUCCESS = "yes" ]; then echo "TESTS PASSED"; else echo "TESTS FAILED"; exit 1; fi
#- name: Upload coverage
Expand Down
14 changes: 10 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
/vendor
/js/
*.bak
node_modules
/css/fontawesome-free
/.idea
.code-workspace
.DS_Store
.idea/
.vscode/
.vscode-upload.json
.*.sw*
/node_modules
/composer.lock
.php*.cache
3 changes: 3 additions & 0 deletions .l10nignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# compiled vue templates
js/
vendor/
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
declare(strict_types=1);

require_once './vendor/autoload.php';

use Nextcloud\CodingStandard\Config;

$config = new Config();
$config
->getFinder()
->notPath('build')
->notPath('l10n')
->notPath('src')
->notPath('node_modules')
->notPath('vendor')
->in(__DIR__);
return $config;
36 changes: 36 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "julien-nc/phonetrack",
"authors": [
{
"name": "Julien Veyssier",
"email": "julien-nc@posteo.net"
}
],
"scripts": {
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"psalm": "psalm.phar --no-cache",
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
"psalm:update-baseline:force": "psalm --threads=1 --update-baseline --set-baseline=tests/psalm-baseline.xml",
"test:unit": "phpunit --config tests/phpunit.xml",
"openapi": "generate-spec --verbose --allow-missing-docs --continue-on-error"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/nextcloud/openapi-extractor"
}
],
"require": {
"php": "^8.0",
"ext-xml": "*"
},
"require-dev": {
"nextcloud/coding-standard": "^1.1",
"psalm/phar": "^5.16",
"nextcloud/ocp": "dev-master",
"phpunit/phpunit": "^9.5",
"nextcloud/openapi-extractor": "dev-feat/openapitype/better-error-messages"
}
}
35 changes: 8 additions & 27 deletions lib/Activity/ActivityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,13 @@
use OCA\PhoneTrack\Db\Device;
use OCP\Activity\IEvent;
use OCP\Activity\IManager;
use OCP\IUserManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\IL10N;
use OCP\IUser;

class ActivityManager {

private $manager;
private $userId;
private $sessionService;
private $sessionMapper;
private $deviceMapper;
private $l10n;

const PHONETRACK_OBJECT_SESSION = 'phonetrack_session';
const PHONETRACK_OBJECT_DEVICE = 'phonetrack_device';

Expand All @@ -59,21 +51,13 @@ class ActivityManager {
const SUBJECT_SESSION_UNSHARE = 'session_unshare';

public function __construct(
IManager $manager,
SessionService $sessionService,
SessionMapper $sessionMapper,
DeviceMapper $deviceMapper,
IL10N $l10n,
IUserManager $userManager,
$userId
private IManager $manager,
private SessionService $sessionService,
private SessionMapper $sessionMapper,
private DeviceMapper $deviceMapper,
private IL10N $l10n,
private ?string $userId,
) {
$this->manager = $manager;
$this->sessionService = $sessionService;
$this->sessionMapper = $sessionMapper;
$this->deviceMapper = $deviceMapper;
$this->l10n = $l10n;
$this->userId = $userId;
$this->userManager = $userManager;
}

/**
Expand Down Expand Up @@ -186,9 +170,6 @@ private function createEvent($objectType, $entity, $subject, $additionalParams =
->setSubject($subject, array_merge($subjectParams, $additionalParams))
->setTimestamp(time());

if ($message !== null) {
$event->setMessage($message);
}
return $event;
}

Expand All @@ -211,7 +192,7 @@ private function sendToUsers(IEvent $event) {
}
/** @var IUser $user */
foreach ($this->sessionService->findUsers($sessionId) as $user) {
$event->setAffectedUser($user);
$event->setAffectedUser($user->getUID());
/** @noinspection DisconnectedForeachInstructionInspection */
$this->manager->publish($event);
}
Expand All @@ -220,7 +201,7 @@ private function sendToUsers(IEvent $event) {
/**
* @param $objectType
* @param $entity
* @return null|\OCA\PhoneTrack\Db\RelationalEntity|\OCP\AppFramework\Db\Entity
* @return null|Session
* @throws \OCP\AppFramework\Db\DoesNotExistException
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
*/
Expand Down
Loading

0 comments on commit fc1ed7f

Please sign in to comment.