diff --git a/.drone.yml b/.drone.yml index 66091fd0..5fcc10e3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -2,25 +2,16 @@ kind: pipeline name: checkers steps: - name: compatibility - image: nextcloudci/php8.0:latest + image: ghcr.io/nextcloud/continuous-integration-php8.0:latest environment: APP_NAME: ldap_write_support - CORE_BRANCH: master + CORE_BRANCH: stable26 DB: sqlite commands: # Pre-setup steps - wget https://raw.githubusercontent.com/nextcloud/travis_ci/master/before_install.sh - bash ./before_install.sh $APP_NAME $CORE_BRANCH $DB - cd ../server - - name: syntax-php8.0 - image: nextcloudci/php8.0:latest - environment: - APP_NAME: ldap_write_support - CORE_BRANCH: stable26 - DB: sqlite - commands: - - composer install - - ./vendor/bin/parallel-lint --exclude ./vendor/ . type: docker trigger: branch: diff --git a/.github/workflows/psalm.yml b/.github/workflows/psalm.yml new file mode 100644 index 00000000..7e56d6e1 --- /dev/null +++ b/.github/workflows/psalm.yml @@ -0,0 +1,42 @@ +# This workflow is provided via the organization template repository +# +# https://github.com/nextcloud/.github +# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization + +name: Static analysis + +on: + pull_request: + push: + branches: + - master + - main + - stable* + +concurrency: + group: psalm-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + static-analysis: + runs-on: ubuntu-latest + + name: Psalm + steps: + - name: Checkout + uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3 + + - name: Set up php + uses: shivammathur/setup-php@1a18b2267f80291a81ca1d33e7c851fe09e7dfc4 # v2 + with: + php-version: 8.1 + coverage: none + ini-file: development + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Install dependencies + run: composer i + + - name: Run coding standards check + run: composer run psalm diff --git a/.nextcloudignore b/.nextcloudignore index 8cb49488..84ecf41b 100644 --- a/.nextcloudignore +++ b/.nextcloudignore @@ -21,3 +21,4 @@ package-lock.json README.md webpack.js img/screenshots +psalm.xml diff --git a/composer.json b/composer.json index 40bccc96..18a65923 100644 --- a/composer.json +++ b/composer.json @@ -2,13 +2,20 @@ "name": "nextcloud/ldap_write_support", "type": "project", "require-dev": { - "php-parallel-lint/php-parallel-lint": "^1.2", - "nextcloud/coding-standard": "^1.0" + "nextcloud/coding-standard": "^1.0", + "nextcloud/ocp": "dev-master", + "vimeo/psalm": "^5.9" }, - "scripts": { - "cs:fix": "php-cs-fixer fix", + "scripts": { + "cs:fix": "php-cs-fixer fix", "cs:check": "php-cs-fixer fix --dry-run --diff", - "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l" + "lint": "find . -name \\*.php -not -path './vendor/*' -not -path './build/*' -not -path './node_modules/*' -print0 | xargs -0 -n1 php -l", + "psalm": "psalm", + "psalm:fix": "psalm --alter --issues=InvalidReturnType,InvalidNullableReturnType,MissingParamType,InvalidFalsableReturnType", + "psalm:update-baseline": "psalm --threads=1 --update-baseline" + }, + "platform": { + "php": "8.0" }, "license": "AGPLv3", "authors": [ diff --git a/composer.lock b/composer.lock index e3cc7441..28740eb4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,9 +4,175 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9d6d243db01220fcbe639058d05b769c", + "content-hash": "4d3a34c75c24bb8a8680dab5e24c5741", "packages": [], "packages-dev": [ + { + "name": "amphp/amp", + "version": "v2.6.2", + "source": { + "type": "git", + "url": "https://github.com/amphp/amp.git", + "reference": "9d5100cebffa729aaffecd3ad25dc5aeea4f13bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/amp/zipball/9d5100cebffa729aaffecd3ad25dc5aeea4f13bb", + "reference": "9d5100cebffa729aaffecd3ad25dc5aeea4f13bb", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "dev-master", + "amphp/phpunit-util": "^1", + "ext-json": "*", + "jetbrains/phpstorm-stubs": "^2019.3", + "phpunit/phpunit": "^7 | ^8 | ^9", + "psalm/phar": "^3.11@dev", + "react/promise": "^2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "files": [ + "lib/functions.php", + "lib/Internal/functions.php" + ], + "psr-4": { + "Amp\\": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniel Lowrey", + "email": "rdlowrey@php.net" + }, + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, + { + "name": "Bob Weinand", + "email": "bobwei9@hotmail.com" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "A non-blocking concurrency framework for PHP applications.", + "homepage": "https://amphp.org/amp", + "keywords": [ + "async", + "asynchronous", + "awaitable", + "concurrency", + "event", + "event-loop", + "future", + "non-blocking", + "promise" + ], + "support": { + "irc": "irc://irc.freenode.org/amphp", + "issues": "https://github.com/amphp/amp/issues", + "source": "https://github.com/amphp/amp/tree/v2.6.2" + }, + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2022-02-20T17:52:18+00:00" + }, + { + "name": "amphp/byte-stream", + "version": "v1.8.1", + "source": { + "type": "git", + "url": "https://github.com/amphp/byte-stream.git", + "reference": "acbd8002b3536485c997c4e019206b3f10ca15bd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/amphp/byte-stream/zipball/acbd8002b3536485c997c4e019206b3f10ca15bd", + "reference": "acbd8002b3536485c997c4e019206b3f10ca15bd", + "shasum": "" + }, + "require": { + "amphp/amp": "^2", + "php": ">=7.1" + }, + "require-dev": { + "amphp/php-cs-fixer-config": "dev-master", + "amphp/phpunit-util": "^1.4", + "friendsofphp/php-cs-fixer": "^2.3", + "jetbrains/phpstorm-stubs": "^2019.3", + "phpunit/phpunit": "^6 || ^7 || ^8", + "psalm/phar": "^3.11.4" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "files": [ + "lib/functions.php" + ], + "psr-4": { + "Amp\\ByteStream\\": "lib" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Aaron Piotrowski", + "email": "aaron@trowski.com" + }, + { + "name": "Niklas Keller", + "email": "me@kelunik.com" + } + ], + "description": "A stream abstraction to make working with non-blocking I/O simple.", + "homepage": "http://amphp.org/byte-stream", + "keywords": [ + "amp", + "amphp", + "async", + "io", + "non-blocking", + "stream" + ], + "support": { + "irc": "irc://irc.freenode.org/amphp", + "issues": "https://github.com/amphp/byte-stream/issues", + "source": "https://github.com/amphp/byte-stream/tree/v1.8.1" + }, + "funding": [ + { + "url": "https://github.com/amphp", + "type": "github" + } + ], + "time": "2021-03-30T17:13:30+00:00" + }, { "name": "composer/pcre", "version": "3.0.0", @@ -225,6 +391,43 @@ ], "time": "2022-02-25T21:32:43+00:00" }, + { + "name": "dnoegel/php-xdg-base-dir", + "version": "v0.1.1", + "source": { + "type": "git", + "url": "https://github.com/dnoegel/php-xdg-base-dir.git", + "reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd", + "reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~7.0|~6.0|~5.0|~4.8.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "XdgBaseDir\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "implementation of xdg base directory specification for php", + "support": { + "issues": "https://github.com/dnoegel/php-xdg-base-dir/issues", + "source": "https://github.com/dnoegel/php-xdg-base-dir/tree/v0.1.1" + }, + "time": "2019-12-04T15:06:13+00:00" + }, { "name": "doctrine/annotations", "version": "1.13.3", @@ -298,6 +501,49 @@ }, "time": "2022-07-02T10:48:51+00:00" }, + { + "name": "doctrine/deprecations", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpunit/phpunit": "^7.5|^8.5|^9.5", + "psr/log": "^1|^2|^3" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/v1.0.0" + }, + "time": "2022-05-02T15:47:09+00:00" + }, { "name": "doctrine/lexer", "version": "1.2.3", @@ -372,68 +618,539 @@ "type": "tidelift" } ], - "time": "2022-02-28T11:07:21+00:00" + "time": "2022-02-28T11:07:21+00:00" + }, + { + "name": "felixfbecker/advanced-json-rpc", + "version": "v3.2.1", + "source": { + "type": "git", + "url": "https://github.com/felixfbecker/php-advanced-json-rpc.git", + "reference": "b5f37dbff9a8ad360ca341f3240dc1c168b45447" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/felixfbecker/php-advanced-json-rpc/zipball/b5f37dbff9a8ad360ca341f3240dc1c168b45447", + "reference": "b5f37dbff9a8ad360ca341f3240dc1c168b45447", + "shasum": "" + }, + "require": { + "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", + "php": "^7.1 || ^8.0", + "phpdocumentor/reflection-docblock": "^4.3.4 || ^5.0.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.0 || ^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "AdvancedJsonRpc\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "ISC" + ], + "authors": [ + { + "name": "Felix Becker", + "email": "felix.b@outlook.com" + } + ], + "description": "A more advanced JSONRPC implementation", + "support": { + "issues": "https://github.com/felixfbecker/php-advanced-json-rpc/issues", + "source": "https://github.com/felixfbecker/php-advanced-json-rpc/tree/v3.2.1" + }, + "time": "2021-06-11T22:34:44+00:00" + }, + { + "name": "felixfbecker/language-server-protocol", + "version": "v1.5.2", + "source": { + "type": "git", + "url": "https://github.com/felixfbecker/php-language-server-protocol.git", + "reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/6e82196ffd7c62f7794d778ca52b69feec9f2842", + "reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "require-dev": { + "phpstan/phpstan": "*", + "squizlabs/php_codesniffer": "^3.1", + "vimeo/psalm": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "LanguageServerProtocol\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "ISC" + ], + "authors": [ + { + "name": "Felix Becker", + "email": "felix.b@outlook.com" + } + ], + "description": "PHP classes for the Language Server Protocol", + "keywords": [ + "language", + "microsoft", + "php", + "server" + ], + "support": { + "issues": "https://github.com/felixfbecker/php-language-server-protocol/issues", + "source": "https://github.com/felixfbecker/php-language-server-protocol/tree/v1.5.2" + }, + "time": "2022-03-02T22:36:06+00:00" + }, + { + "name": "fidry/cpu-core-counter", + "version": "0.5.1", + "source": { + "type": "git", + "url": "https://github.com/theofidry/cpu-core-counter.git", + "reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/cpu-core-counter/zipball/b58e5a3933e541dc286cc91fc4f3898bbc6f1623", + "reference": "b58e5a3933e541dc286cc91fc4f3898bbc6f1623", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "fidry/makefile": "^0.2.0", + "phpstan/extension-installer": "^1.2.0", + "phpstan/phpstan": "^1.9.2", + "phpstan/phpstan-deprecation-rules": "^1.0.0", + "phpstan/phpstan-phpunit": "^1.2.2", + "phpstan/phpstan-strict-rules": "^1.4.4", + "phpunit/phpunit": "^9.5.26 || ^8.5.31", + "theofidry/php-cs-fixer-config": "^1.0", + "webmozarts/strict-phpunit": "^7.5" + }, + "type": "library", + "autoload": { + "psr-4": { + "Fidry\\CpuCoreCounter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com" + } + ], + "description": "Tiny utility to get the number of CPU cores.", + "keywords": [ + "CPU", + "core" + ], + "support": { + "issues": "https://github.com/theofidry/cpu-core-counter/issues", + "source": "https://github.com/theofidry/cpu-core-counter/tree/0.5.1" + }, + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2022-12-24T12:35:10+00:00" + }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v3.11.0", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "7dcdea3f2f5f473464e835be9be55283ff8cfdc3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/7dcdea3f2f5f473464e835be9be55283ff8cfdc3", + "reference": "7dcdea3f2f5f473464e835be9be55283ff8cfdc3", + "shasum": "" + }, + "require": { + "composer/semver": "^3.2", + "composer/xdebug-handler": "^3.0.3", + "doctrine/annotations": "^1.13", + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^7.4 || ^8.0", + "sebastian/diff": "^4.0", + "symfony/console": "^5.4 || ^6.0", + "symfony/event-dispatcher": "^5.4 || ^6.0", + "symfony/filesystem": "^5.4 || ^6.0", + "symfony/finder": "^5.4 || ^6.0", + "symfony/options-resolver": "^5.4 || ^6.0", + "symfony/polyfill-mbstring": "^1.23", + "symfony/polyfill-php80": "^1.25", + "symfony/polyfill-php81": "^1.25", + "symfony/process": "^5.4 || ^6.0", + "symfony/stopwatch": "^5.4 || ^6.0" + }, + "require-dev": { + "justinrainbow/json-schema": "^5.2", + "keradus/cli-executor": "^1.5", + "mikey179/vfsstream": "^1.6.10", + "php-coveralls/php-coveralls": "^2.5.2", + "php-cs-fixer/accessible-object": "^1.1", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", + "phpspec/prophecy": "^1.15", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", + "phpunitgoodpractices/polyfill": "^1.5", + "phpunitgoodpractices/traits": "^1.9.1", + "symfony/phpunit-bridge": "^6.0", + "symfony/yaml": "^5.4 || ^6.0" + }, + "suggest": { + "ext-dom": "For handling output formats in XML", + "ext-mbstring": "For handling non-UTF8 characters." + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz Rumiński", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "support": { + "issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues", + "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v3.11.0" + }, + "funding": [ + { + "url": "https://github.com/keradus", + "type": "github" + } + ], + "time": "2022-09-01T18:24:51+00:00" + }, + { + "name": "netresearch/jsonmapper", + "version": "v4.1.0", + "source": { + "type": "git", + "url": "https://github.com/cweiske/jsonmapper.git", + "reference": "cfa81ea1d35294d64adb9c68aa4cb9e92400e53f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/cweiske/jsonmapper/zipball/cfa81ea1d35294d64adb9c68aa4cb9e92400e53f", + "reference": "cfa81ea1d35294d64adb9c68aa4cb9e92400e53f", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-pcre": "*", + "ext-reflection": "*", + "ext-spl": "*", + "php": ">=7.1" + }, + "require-dev": { + "phpunit/phpunit": "~7.5 || ~8.0 || ~9.0", + "squizlabs/php_codesniffer": "~3.5" + }, + "type": "library", + "autoload": { + "psr-0": { + "JsonMapper": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "OSL-3.0" + ], + "authors": [ + { + "name": "Christian Weiske", + "email": "cweiske@cweiske.de", + "homepage": "http://github.com/cweiske/jsonmapper/", + "role": "Developer" + } + ], + "description": "Map nested JSON structures onto PHP classes", + "support": { + "email": "cweiske@cweiske.de", + "issues": "https://github.com/cweiske/jsonmapper/issues", + "source": "https://github.com/cweiske/jsonmapper/tree/v4.1.0" + }, + "time": "2022-12-08T20:46:14+00:00" + }, + { + "name": "nextcloud/coding-standard", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/nextcloud/coding-standard.git", + "reference": "f3d1f9375e89c605deb1734f59a9f51ecbe80578" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/f3d1f9375e89c605deb1734f59a9f51ecbe80578", + "reference": "f3d1f9375e89c605deb1734f59a9f51ecbe80578", + "shasum": "" + }, + "require": { + "friendsofphp/php-cs-fixer": "^3.2", + "php": "^7.3|^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Nextcloud\\CodingStandard\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + } + ], + "description": "Nextcloud coding standards for the php cs fixer", + "support": { + "issues": "https://github.com/nextcloud/coding-standard/issues", + "source": "https://github.com/nextcloud/coding-standard/tree/v1.0.0" + }, + "time": "2021-11-10T08:44:10+00:00" + }, + { + "name": "nextcloud/ocp", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/nextcloud-deps/ocp.git", + "reference": "f94a54bc76497a9ce231c47bb5e43f6a64282a39" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/f94a54bc76497a9ce231c47bb5e43f6a64282a39", + "reference": "f94a54bc76497a9ce231c47bb5e43f6a64282a39", + "shasum": "" + }, + "require": { + "php": "^7.4 || ~8.0 || ~8.1", + "psr/clock": "^1.0", + "psr/container": "^1.1.1", + "psr/event-dispatcher": "^1.0", + "psr/log": "^1.1" + }, + "default-branch": true, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "26.0.0-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "AGPL-3.0-or-later" + ], + "authors": [ + { + "name": "Christoph Wurst", + "email": "christoph@winzerhof-wurst.at" + } + ], + "description": "Composer package containing Nextcloud's public API (classes, interfaces)", + "support": { + "issues": "https://github.com/nextcloud-deps/ocp/issues", + "source": "https://github.com/nextcloud-deps/ocp/tree/master" + }, + "time": "2023-04-02T00:37:55+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.15.4", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/6bb5176bc4af8bcb7d926f88718db9b96a2d4290", + "reference": "6bb5176bc4af8bcb7d926f88718db9b96a2d4290", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.4" + }, + "time": "2023-03-05T19:49:14+00:00" + }, + { + "name": "phpdocumentor/reflection-common", + "version": "2.2.0", + "source": { + "type": "git", + "url": "https://github.com/phpDocumentor/ReflectionCommon.git", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionCommon/zipball/1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "reference": "1d01c49d4ed62f25aa84a747ad35d5a16924662b", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-2.x": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "phpDocumentor\\Reflection\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jaap van Otterdijk", + "email": "opensource@ijaap.nl" + } + ], + "description": "Common reflection classes used by phpdocumentor to reflect the code structure", + "homepage": "http://www.phpdoc.org", + "keywords": [ + "FQSEN", + "phpDocumentor", + "phpdoc", + "reflection", + "static analysis" + ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, + "time": "2020-06-27T09:03:43+00:00" }, { - "name": "friendsofphp/php-cs-fixer", - "version": "v3.11.0", + "name": "phpdocumentor/reflection-docblock", + "version": "5.3.0", "source": { "type": "git", - "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", - "reference": "7dcdea3f2f5f473464e835be9be55283ff8cfdc3" + "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/7dcdea3f2f5f473464e835be9be55283ff8cfdc3", - "reference": "7dcdea3f2f5f473464e835be9be55283ff8cfdc3", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", "shasum": "" }, "require": { - "composer/semver": "^3.2", - "composer/xdebug-handler": "^3.0.3", - "doctrine/annotations": "^1.13", - "ext-json": "*", - "ext-tokenizer": "*", - "php": "^7.4 || ^8.0", - "sebastian/diff": "^4.0", - "symfony/console": "^5.4 || ^6.0", - "symfony/event-dispatcher": "^5.4 || ^6.0", - "symfony/filesystem": "^5.4 || ^6.0", - "symfony/finder": "^5.4 || ^6.0", - "symfony/options-resolver": "^5.4 || ^6.0", - "symfony/polyfill-mbstring": "^1.23", - "symfony/polyfill-php80": "^1.25", - "symfony/polyfill-php81": "^1.25", - "symfony/process": "^5.4 || ^6.0", - "symfony/stopwatch": "^5.4 || ^6.0" + "ext-filter": "*", + "php": "^7.2 || ^8.0", + "phpdocumentor/reflection-common": "^2.2", + "phpdocumentor/type-resolver": "^1.3", + "webmozart/assert": "^1.9.1" }, "require-dev": { - "justinrainbow/json-schema": "^5.2", - "keradus/cli-executor": "^1.5", - "mikey179/vfsstream": "^1.6.10", - "php-coveralls/php-coveralls": "^2.5.2", - "php-cs-fixer/accessible-object": "^1.1", - "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.2", - "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.2.1", - "phpspec/prophecy": "^1.15", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5", - "phpunitgoodpractices/polyfill": "^1.5", - "phpunitgoodpractices/traits": "^1.9.1", - "symfony/phpunit-bridge": "^6.0", - "symfony/yaml": "^5.4 || ^6.0" + "mockery/mockery": "~1.3.2", + "psalm/phar": "^4.8" }, - "suggest": { - "ext-dom": "For handling output formats in XML", - "ext-mbstring": "For handling non-UTF8 characters." + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev" + } }, - "bin": [ - "php-cs-fixer" - ], - "type": "application", "autoload": { "psr-4": { - "PhpCsFixer\\": "src/" + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -442,49 +1159,60 @@ ], "authors": [ { - "name": "Fabien Potencier", - "email": "fabien@symfony.com" + "name": "Mike van Riel", + "email": "me@mikevanriel.com" }, { - "name": "Dariusz Rumiński", - "email": "dariusz.ruminski@gmail.com" + "name": "Jaap van Otterdijk", + "email": "account@ijaap.nl" } ], - "description": "A tool to automatically fix PHP code style", + "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", "support": { - "issues": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues", - "source": "https://github.com/FriendsOfPHP/PHP-CS-Fixer/tree/v3.11.0" + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/5.3.0" }, - "funding": [ - { - "url": "https://github.com/keradus", - "type": "github" - } - ], - "time": "2022-09-01T18:24:51+00:00" + "time": "2021-10-19T17:43:47+00:00" }, { - "name": "nextcloud/coding-standard", - "version": "v1.0.0", + "name": "phpdocumentor/type-resolver", + "version": "1.7.1", "source": { "type": "git", - "url": "https://github.com/nextcloud/coding-standard.git", - "reference": "f3d1f9375e89c605deb1734f59a9f51ecbe80578" + "url": "https://github.com/phpDocumentor/TypeResolver.git", + "reference": "dfc078e8af9c99210337325ff5aa152872c98714" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nextcloud/coding-standard/zipball/f3d1f9375e89c605deb1734f59a9f51ecbe80578", - "reference": "f3d1f9375e89c605deb1734f59a9f51ecbe80578", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/dfc078e8af9c99210337325ff5aa152872c98714", + "reference": "dfc078e8af9c99210337325ff5aa152872c98714", "shasum": "" }, "require": { - "friendsofphp/php-cs-fixer": "^3.2", - "php": "^7.3|^8.0" + "doctrine/deprecations": "^1.0", + "php": "^7.4 || ^8.0", + "phpdocumentor/reflection-common": "^2.0", + "phpstan/phpdoc-parser": "^1.13" + }, + "require-dev": { + "ext-tokenizer": "*", + "phpbench/phpbench": "^1.2", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.8", + "phpstan/phpstan-phpunit": "^1.1", + "phpunit/phpunit": "^9.5", + "rector/rector": "^0.13.9", + "vimeo/psalm": "^4.25" }, "type": "library", + "extra": { + "branch-alias": { + "dev-1.x": "1.x-dev" + } + }, "autoload": { "psr-4": { - "Nextcloud\\CodingStandard\\": "src" + "phpDocumentor\\Reflection\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -493,73 +1221,61 @@ ], "authors": [ { - "name": "Christoph Wurst", - "email": "christoph@winzerhof-wurst.at" + "name": "Mike van Riel", + "email": "me@mikevanriel.com" } ], - "description": "Nextcloud coding standards for the php cs fixer", + "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { - "issues": "https://github.com/nextcloud/coding-standard/issues", - "source": "https://github.com/nextcloud/coding-standard/tree/v1.0.0" + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.7.1" }, - "time": "2021-11-10T08:44:10+00:00" + "time": "2023-03-27T19:02:04+00:00" }, { - "name": "php-parallel-lint/php-parallel-lint", - "version": "v1.2.0", + "name": "phpstan/phpdoc-parser", + "version": "1.16.1", "source": { "type": "git", - "url": "https://github.com/php-parallel-lint/PHP-Parallel-Lint.git", - "reference": "474f18bc6cc6aca61ca40bfab55139de614e51ca" + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "e27e92d939e2e3636f0a1f0afaba59692c0bf571" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-parallel-lint/PHP-Parallel-Lint/zipball/474f18bc6cc6aca61ca40bfab55139de614e51ca", - "reference": "474f18bc6cc6aca61ca40bfab55139de614e51ca", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/e27e92d939e2e3636f0a1f0afaba59692c0bf571", + "reference": "e27e92d939e2e3636f0a1f0afaba59692c0bf571", "shasum": "" }, "require": { - "ext-json": "*", - "php": ">=5.4.0" - }, - "replace": { - "grogy/php-parallel-lint": "*", - "jakub-onderka/php-parallel-lint": "*" + "php": "^7.2 || ^8.0" }, "require-dev": { - "nette/tester": "^1.3 || ^2.0", - "php-parallel-lint/php-console-highlighter": "~0.3", - "squizlabs/php_codesniffer": "~3.0" - }, - "suggest": { - "php-parallel-lint/php-console-highlighter": "Highlight syntax in code snippet" + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-phpunit": "^1.1", + "phpstan/phpstan-strict-rules": "^1.0", + "phpunit/phpunit": "^9.5", + "symfony/process": "^5.2" }, - "bin": [ - "parallel-lint" - ], "type": "library", "autoload": { - "classmap": [ - "./" - ] + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-2-Clause" - ], - "authors": [ - { - "name": "Jakub Onderka", - "email": "ahoj@jakubonderka.cz" - } + "MIT" ], - "description": "This tool check syntax of PHP files about 20x faster than serial check.", - "homepage": "https://github.com/php-parallel-lint/PHP-Parallel-Lint", + "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { - "issues": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/issues", - "source": "https://github.com/php-parallel-lint/PHP-Parallel-Lint/tree/master" + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.16.1" }, - "time": "2020-04-04T12:18:32+00:00" + "time": "2023-02-07T18:11:17+00:00" }, { "name": "psr/cache", @@ -610,6 +1326,54 @@ }, "time": "2016-08-06T20:24:11+00:00" }, + { + "name": "psr/clock", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-fig/clock.git", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Psr\\Clock\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for reading the clock.", + "homepage": "https://github.com/php-fig/clock", + "keywords": [ + "clock", + "now", + "psr", + "psr-20", + "time" + ], + "support": { + "issues": "https://github.com/php-fig/clock/issues", + "source": "https://github.com/php-fig/clock/tree/1.0.0" + }, + "time": "2022-11-25T14:36:26+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -824,6 +1588,69 @@ ], "time": "2020-10-26T13:10:38+00:00" }, + { + "name": "spatie/array-to-xml", + "version": "3.1.5", + "source": { + "type": "git", + "url": "https://github.com/spatie/array-to-xml.git", + "reference": "13f76acef5362d15c71ae1ac6350cc3df5e25e43" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/array-to-xml/zipball/13f76acef5362d15c71ae1ac6350cc3df5e25e43", + "reference": "13f76acef5362d15c71ae1ac6350cc3df5e25e43", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.2", + "pestphp/pest": "^1.21", + "spatie/pest-plugin-snapshots": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\ArrayToXml\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "homepage": "https://freek.dev", + "role": "Developer" + } + ], + "description": "Convert an array to xml", + "homepage": "https://github.com/spatie/array-to-xml", + "keywords": [ + "array", + "convert", + "xml" + ], + "support": { + "source": "https://github.com/spatie/array-to-xml/tree/3.1.5" + }, + "funding": [ + { + "url": "https://spatie.be/open-source/support-us", + "type": "custom" + }, + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2022-12-24T13:43:51+00:00" + }, { "name": "symfony/console", "version": "v5.4.13", @@ -2213,11 +3040,177 @@ } ], "time": "2022-09-01T01:52:16+00:00" + }, + { + "name": "vimeo/psalm", + "version": "5.9.0", + "source": { + "type": "git", + "url": "https://github.com/vimeo/psalm.git", + "reference": "8b9ad1eb9e8b7d3101f949291da2b9f7767cd163" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/8b9ad1eb9e8b7d3101f949291da2b9f7767cd163", + "reference": "8b9ad1eb9e8b7d3101f949291da2b9f7767cd163", + "shasum": "" + }, + "require": { + "amphp/amp": "^2.4.2", + "amphp/byte-stream": "^1.5", + "composer-runtime-api": "^2", + "composer/semver": "^1.4 || ^2.0 || ^3.0", + "composer/xdebug-handler": "^2.0 || ^3.0", + "dnoegel/php-xdg-base-dir": "^0.1.1", + "ext-ctype": "*", + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-simplexml": "*", + "ext-tokenizer": "*", + "felixfbecker/advanced-json-rpc": "^3.1", + "felixfbecker/language-server-protocol": "^1.5.2", + "fidry/cpu-core-counter": "^0.4.1 || ^0.5.1", + "netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0", + "nikic/php-parser": "^4.14", + "php": "^7.4 || ~8.0.0 || ~8.1.0 || ~8.2.0", + "sebastian/diff": "^4.0 || ^5.0", + "spatie/array-to-xml": "^2.17.0 || ^3.0", + "symfony/console": "^4.1.6 || ^5.0 || ^6.0", + "symfony/filesystem": "^5.4 || ^6.0" + }, + "provide": { + "psalm/psalm": "self.version" + }, + "require-dev": { + "amphp/phpunit-util": "^2.0", + "bamarni/composer-bin-plugin": "^1.4", + "brianium/paratest": "^6.9", + "ext-curl": "*", + "mockery/mockery": "^1.5", + "nunomaduro/mock-final-classes": "^1.1", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpdoc-parser": "^1.6", + "phpunit/phpunit": "^9.6", + "psalm/plugin-mockery": "^1.1", + "psalm/plugin-phpunit": "^0.18", + "slevomat/coding-standard": "^8.4", + "squizlabs/php_codesniffer": "^3.6", + "symfony/process": "^4.4 || ^5.0 || ^6.0" + }, + "suggest": { + "ext-curl": "In order to send data to shepherd", + "ext-igbinary": "^2.0.5 is required, used to serialize caching data" + }, + "bin": [ + "psalm", + "psalm-language-server", + "psalm-plugin", + "psalm-refactor", + "psalter" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.x-dev", + "dev-4.x": "4.x-dev", + "dev-3.x": "3.x-dev", + "dev-2.x": "2.x-dev", + "dev-1.x": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psalm\\": "src/Psalm/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Matthew Brown" + } + ], + "description": "A static analysis tool for finding errors in PHP applications", + "keywords": [ + "code", + "inspection", + "php", + "static analysis" + ], + "support": { + "issues": "https://github.com/vimeo/psalm/issues", + "source": "https://github.com/vimeo/psalm/tree/5.9.0" + }, + "time": "2023-03-29T21:38:21+00:00" + }, + { + "name": "webmozart/assert", + "version": "1.11.0", + "source": { + "type": "git", + "url": "https://github.com/webmozarts/assert.git", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webmozarts/assert/zipball/11cb2199493b2f8a3b53e7f19068fc6aac760991", + "reference": "11cb2199493b2f8a3b53e7f19068fc6aac760991", + "shasum": "" + }, + "require": { + "ext-ctype": "*", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "phpstan/phpstan": "<0.12.20", + "vimeo/psalm": "<4.6.1 || 4.6.2" + }, + "require-dev": { + "phpunit/phpunit": "^8.5.13" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "psr-4": { + "Webmozart\\Assert\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Assertions to validate method input/output with nice error messages.", + "keywords": [ + "assert", + "check", + "validate" + ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.11.0" + }, + "time": "2022-06-03T18:03:27+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "nextcloud/ocp": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": [], diff --git a/lib/LDAPConnect.php b/lib/LDAPConnect.php index 1612b5f2..fbe96817 100644 --- a/lib/LDAPConnect.php +++ b/lib/LDAPConnect.php @@ -42,7 +42,7 @@ public function __construct(Helper $ldapBackendHelper, LoggerInterface $logger) } /** - * @return bool|resource + * @return resource|\LDAP\Connection * @throws ServerNotAvailableException */ public function connect() { @@ -50,41 +50,39 @@ public function connect() { $ldapPort = $this->ldapConfig->ldapPort; // shamelessly copied from OCA\User_LDAP\LDAP::connect() - if (strpos($ldapHost, '://') === false) { + $pos = strpos($ldapHost, '://'); + if ($pos === false) { $ldapHost = 'ldap://' . $ldapHost; + $pos = 4; } - if (strpos($ldapHost, ':', strpos($ldapHost, '://') + 1) === false) { + if (strpos($ldapHost, ':', $pos + 1) === false && !empty($ldapPort)) { $ldapHost .= ':' . $ldapPort; } // Connecting to LDAP - TODO: connect directly via LDAP plugin $cr = ldap_connect($ldapHost); if (!is_resource($cr) && !is_object($cr)) { - throw new ServerNotAvailableException('LDAP server not available'); - } - - if ($cr) { - ldap_set_option($cr, LDAP_OPT_PROTOCOL_VERSION, 3); - $this->logger->debug('Connected to LDAP host {ldapHost}:{ldapPort}', - [ - 'app' => Application::APP_ID, - 'ldapHost' => $ldapHost, - 'ldapPort' => $ldapPort, - ]); - return $cr; - } else { $this->logger->error('Unable to connect to LDAP host {ldapHost}:{ldapPort}', [ 'app' => Application::APP_ID, 'ldapHost' => $ldapHost, 'ldapPort' => $ldapPort, ]); - return false; + throw new ServerNotAvailableException('LDAP server not available'); } + + ldap_set_option($cr, LDAP_OPT_PROTOCOL_VERSION, 3); + $this->logger->debug('Connected to LDAP host {ldapHost}:{ldapPort}', + [ + 'app' => Application::APP_ID, + 'ldapHost' => $ldapHost, + 'ldapPort' => $ldapPort, + ]); + return $cr; } /** - * @return bool|resource + * @return false|resource|\LDAP\Connection * @throws ServerNotAvailableException */ public function bind() { @@ -107,7 +105,7 @@ public function bind() { } /** - * @return bool|resource + * @return false|resource|\LDAP\Connection * @throws ServerNotAvailableException */ public function getLDAPConnection() { diff --git a/lib/LDAPGroupManager.php b/lib/LDAPGroupManager.php index 8216c6a9..c7d5aa77 100644 --- a/lib/LDAPGroupManager.php +++ b/lib/LDAPGroupManager.php @@ -26,10 +26,10 @@ namespace OCA\LdapWriteSupport; use Exception; -use OC\Group\Backend; use OCA\LdapWriteSupport\AppInfo\Application; use OCA\User_LDAP\Group_Proxy; use OCA\User_LDAP\ILDAPGroupPlugin; +use OCP\GroupInterface; use OCP\IGroupManager; use OCP\LDAP\ILDAPProvider; use Psr\Log\LoggerInterface; @@ -58,22 +58,19 @@ public function __construct(IGroupManager $groupManager, LDAPConnect $ldapConnec } /** - * Check if plugin implements actions - * - * @param int $actions bitwise-or'ed actions - * @return boolean - * * Returns the supported actions as int to be * compared with OC_GROUP_BACKEND_CREATE_GROUP etc. + * + * @return int bitwise-or'ed actions */ public function respondToActions() { if (!$this->ldapConnect->groupsEnabled()) { return 0; } - return Backend::CREATE_GROUP | - Backend::DELETE_GROUP | - Backend::ADD_TO_GROUP | - Backend::REMOVE_FROM_GROUP; + return GroupInterface::CREATE_GROUP | + GroupInterface::DELETE_GROUP | + GroupInterface::ADD_TO_GROUP | + GroupInterface::REMOVE_FROM_GROUP; } /** @@ -91,14 +88,15 @@ public function createGroup($gid) { $newGroupDN = "cn=$gid," . $this->ldapConnect->getLDAPBaseGroups()[0]; $newGroupDN = $this->ldapProvider->sanitizeDN([$newGroupDN])[0]; - if ($ret = ldap_add($connection, $newGroupDN, $newGroupEntry)) { + if ($connection && ($ret = ldap_add($connection, $newGroupDN, $newGroupEntry))) { $message = "Create LDAP group '$gid' ($newGroupDN)"; $this->logger->notice($message, ['app' => Application::APP_ID]); + return $newGroupDN; } else { $message = "Unable to create LDAP group '$gid' ($newGroupDN)"; $this->logger->error($message, ['app' => Application::APP_ID]); + return null; } - return $ret ? $newGroupDN : null; } /** diff --git a/lib/LDAPUserManager.php b/lib/LDAPUserManager.php index d623c8ff..98e4824a 100644 --- a/lib/LDAPUserManager.php +++ b/lib/LDAPUserManager.php @@ -26,7 +26,6 @@ namespace OCA\LdapWriteSupport; use Exception; -use OC\HintException; use OC\ServerNotAvailableException; use OC\User\Backend; use OC_User; @@ -35,6 +34,7 @@ use OCA\User_LDAP\Exceptions\ConstraintViolationException; use OCA\User_LDAP\ILDAPUserPlugin; use OCA\User_LDAP\IUserLDAP; +use OCP\HintException; use OCP\IImage; use OCP\IL10N; use OCP\IUser; @@ -78,13 +78,10 @@ public function __construct(IUserManager $userManager, IUserSession $userSession } /** - * Check if plugin implements actions - * - * @param int $actions bitwise-or'ed actions - * @return boolean - * * Returns the supported actions as int to be * compared with OC_USER_BACKEND_CREATE_USER etc. + * + * @return int bitwise-or'ed actions */ public function respondToActions() { $setPassword = function_exists('ldap_exop_passwd') && !$this->ldapConnect->hasPasswordPolicy() @@ -253,22 +250,20 @@ public function createUser($username, $password) { $ret = ldap_exop_passwd($connection, $newUserDN, '', $password); if ($ret === false) { $message = 'ldap_exop_passwd failed, falling back to ldap_mod_replace to to set password for new user'; - $this->logger->log(ILogger::DEBUG, $message, [ - 'app' => Application::APP_ID, - ]); + $this->logger->debug($message, ['app' => Application::APP_ID]); // Fallback to `userPassword` in case the server does not support exop_passwd $ret = ldap_mod_replace($connection, $newUserDN, ['userPassword' => $password]); if ($ret === false) { $message = 'Failed to set password for new user {dn}'; - $this->logger->log(ILogger::ERROR, $message, [ + $this->logger->error($message, [ 'app' => Application::APP_ID, 'dn' => $newUserDN, ]); } } } catch (\Exception $e) { - $this->logger->logException($e, ['app' => Application::APP_ID]); + $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => Application::APP_ID]); } } return $ret ? $newUserDN : false; @@ -374,9 +369,9 @@ public function setPassword($uid, $password) { try { $cr = $this->ldapProvider->getLDAPConnection($uid); $userDN = $this->getUserDN($uid); - return ldap_exop_passwd($cr, $userDN, '', $password); + return ldap_exop_passwd($cr, $userDN, '', $password) !== false; } catch (\Exception $e) { - $this->logger->logException($e, ['app' => Application::APP_ID]); + $this->logger->error($e->getMessage(), ['exception' => $e, 'app' => Application::APP_ID]); } return false; } @@ -400,7 +395,7 @@ public function getHome($uid) { */ public function getDisplayName($uid) { // Not implemented - return false; + return $uid; } /** diff --git a/lib/Listener/GroupBackendRegisteredListener.php b/lib/Listener/GroupBackendRegisteredListener.php index 9eaba7fa..563541e2 100644 --- a/lib/Listener/GroupBackendRegisteredListener.php +++ b/lib/Listener/GroupBackendRegisteredListener.php @@ -31,6 +31,9 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +/** + * @template-implements IEventListener + */ class GroupBackendRegisteredListener implements IEventListener { /** @var IAppManager */ private $appManager; diff --git a/lib/Listener/UserBackendRegisteredListener.php b/lib/Listener/UserBackendRegisteredListener.php index 396f3334..afafad1c 100644 --- a/lib/Listener/UserBackendRegisteredListener.php +++ b/lib/Listener/UserBackendRegisteredListener.php @@ -31,6 +31,9 @@ use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; +/** + * @template-implements IEventListener + */ class UserBackendRegisteredListener implements IEventListener { /** @var IAppManager */ private $appManager; diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..7d18a32d --- /dev/null +++ b/psalm.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml new file mode 100644 index 00000000..210d4183 --- /dev/null +++ b/tests/psalm-baseline.xml @@ -0,0 +1,33 @@ + + + + + GroupBackendRegisteredListener::class + UserBackendRegisteredListener::class + + + + + ldapConfig->ldapGroupFilter]]> + ldapConfig->ldapGroupMemberAssocAttr]]> + + + !is_resource($cr) + + + + + canChangeAvatar + countUsers + createUser + getDisplayName + getHome + respondToActions + setDisplayName + setPassword + + + listen + + + diff --git a/tests/stubs/stub.phpstub b/tests/stubs/stub.phpstub new file mode 100644 index 00000000..b0c78ca4 --- /dev/null +++ b/tests/stubs/stub.phpstub @@ -0,0 +1,239 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +class OC_User { + public static function useBackend(string|\OCP\UserInterface $backend = 'database'): bool; +} + +namespace OC\User { + abstract class Backend { + public const NOT_IMPLEMENTED = -501; + public const CREATE_USER = 1; // 1 << 0 + public const SET_PASSWORD = 16; // 1 << 4 + public const CHECK_PASSWORD = 256; // 1 << 8 + public const GET_HOME = 4096; // 1 << 12 + public const GET_DISPLAYNAME = 65536; // 1 << 16 + public const SET_DISPLAYNAME = 1048576; // 1 << 20 + public const PROVIDE_AVATAR = 16777216; // 1 << 24 + public const COUNT_USERS = 268435456; // 1 << 28 + } +} + +namespace OCA\User_LDAP\Events { + class UserBackendRegistered extends \OCP\EventDispatcher\Event { + public function getBackend(): \OCA\User_LDAP\IUserLDAP; + public function getPluginManager(): \OCA\User_LDAP\UserPluginManager; + } + class GroupBackendRegistered extends \OCP\EventDispatcher\Event { + public function getPluginManager(): \OCA\User_LDAP\GroupPluginManager; + } +} + +namespace OCA\User_LDAP\Exceptions { + class ConstraintViolationException extends \Exception { + } +} + +namespace OCA\User_LDAP\Mapping { + class AbstractMapping { + /** + * @param string $name + * @return string|false + */ + public function getDNByName($name); + + /** + * @param string $fdn + * @return string|false + */ + public function getNameByDN($fdn); + } +} + +namespace OCA\User_LDAP { + interface IUserLDAP { + } + class UserPluginManager { + public function register(ILDAPUserPlugin $plugin): void; + } + interface ILDAPUserPlugin { + /** + * @return int + */ + public function respondToActions(); + + /** + * @param string $uid The UID of the user to create + * @param string $password The password of the new user + * @return bool|string + */ + public function createUser($uid, $password); + + /** + * @param string $uid The username + * @param string $password The new password + * @return bool + */ + public function setPassword($uid, $password); + + /** + * @param string $uid the username + * @return bool + */ + public function getHome($uid); + + /** + * @param string $uid user ID of the user + * @return string display name + */ + public function getDisplayName($uid); + + /** + * @param string $uid user ID of the user + * @param string $displayName new user's display name + * @return string display name + */ + public function setDisplayName($uid, $displayName); + + /** + * @param string $uid the Nextcloud user name + * @return bool either the user can or cannot + */ + public function canChangeAvatar($uid); + + /** + * @return int|false + */ + public function countUsers(); + } + class GroupPluginManager { + public function register(ILDAPGroupPlugin $plugin): void; + } + interface ILDAPGroupPlugin { + } + class Access { + /** + * @throws \Exception + */ + public function getUserMapper(): \OCA\User_LDAP\Mapping\AbstractMapping; + + /** + * @throws \Exception + */ + public function getGroupMapper(): \OCA\User_LDAP\Mapping\AbstractMapping; + + /** + * returns the Connection instance + * + * @return \OCA\User_LDAP\Connection + */ + public function getConnection(); + + /** + * @return array[] + */ + public function fetchListOfGroups(string $filter, array $attr, int $limit = null, int $offset = null): array; + } + /** + * magic properties (incomplete) + * responsible for LDAP connections in context with the provided configuration + * + * @property string ldapHost + * @property string ldapPort holds the port number + * @property string ldapUserFilter + * @property string ldapUserDisplayName + * @property string ldapUserDisplayName2 + * @property string ldapUserAvatarRule + * @property boolean turnOnPasswordChange + * @property string[] ldapBaseUsers + * @property int|null ldapPagingSize holds an integer + * @property bool|mixed|void ldapGroupMemberAssocAttr + * @property string ldapUuidUserAttribute + * @property string ldapUuidGroupAttribute + * @property string ldapExpertUUIDUserAttr + * @property string ldapExpertUUIDGroupAttr + * @property string ldapQuotaAttribute + * @property string ldapQuotaDefault + * @property string ldapEmailAttribute + * @property string ldapExtStorageHomeAttribute + * @property string homeFolderNamingRule + * @property bool|string ldapNestedGroups + * @property string[] ldapBaseGroups + * @property string ldapLoginFilter + * @property string ldapDynamicGroupMemberURL + * @property string ldapGidNumber + * @property int hasMemberOfFilterSupport + * @property int useMemberOfToDetectMembership + * @property string ldapMatchingRuleInChainState + */ + class Connection { + public string $ldapGroupFilter; + public string $ldapGroupDisplayName; + /** + * @return resource|\LDAP\Connection The LDAP resource + */ + public function getConnectionResource(); + } + class Configuration { + public string $ldapAgentName; + public string $ldapAgentPassword; + public array $ldapBase; + public array $ldapBaseUsers; + public array $ldapBaseGroups; + public string $ldapUserDisplayName; + public string $ldapGroupFilter; + public string $ldapGroupMemberAssocAttr; + public string $ldapDefaultPPolicyDN; + public string $ldapHost; + public string $ldapPort; + public function __construct(string $configPrefix, bool $autoRead = true); + } + abstract class Proxy { + /** + * @param string $id + * @return Access + */ + abstract public function getLDAPAccess($id); + } + class Group_Proxy extends Proxy { + } + class Helper { + /** + * returns prefixes for each saved LDAP/AD server configuration. + * + * @param bool $activeConfigurations optional, whether only active configuration shall be + * retrieved, defaults to false + * @return array with a list of the available prefixes + */ + public function getServerConfigurationPrefixes(bool $activeConfigurations = false): array; + } +} + +namespace OC { + class SubAdmin { + public function getAllSubAdmins(): array; + } + class ServerNotAvailableException extends \Exception { + } +}