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 code to access remote Case entity #27

Merged
merged 2 commits into from
Aug 9, 2024
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
45 changes: 45 additions & 0 deletions .github/workflows/phpcs_case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PHP_CodeSniffer - civiremote_case

on:
pull_request:
paths:
- 'modules/civiremote_case/src/**.php'
- modules/civiremote_case/composer.json
- modules/civiremote_case/phpcs.xml.dist

jobs:
phpcs:
runs-on: ubuntu-latest
name: PHP_CodeSniffer
defaults:
run:
working-directory: modules/civiremote_case

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
coverage: none
tools: cs2pr
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('modules/civiremote_case/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer update --no-progress --prefer-dist

- name: Run PHP_CodeSniffer
run: composer phpcs -- -q --report=checkstyle | cs2pr
55 changes: 55 additions & 0 deletions .github/workflows/phpstan_case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: PHPStan - civiremote_case

on:
pull_request:
paths:
- 'modules/civiremote_case/src/**.php'
- modules/civiremote_case/composer.json
- modules/civiremote_case/tools/phpstan/composer.json
- modules/civiremote_case/ci/composer.json
- modules/civiremote_case/phpstan.ci.neon
- modules/civiremote_case/phpstan.neon.dist
- 'modules/civiremote_entity/src/**.php'

jobs:
phpstan:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1', '8.3']
prefer: ['prefer-stable', 'prefer-lowest']
name: PHPStan with PHP ${{ matrix.php-versions }} ${{ matrix.prefer }}
defaults:
run:
working-directory: modules/civiremote_case

steps:
- uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
coverage: none
env:
fail-fast: true

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.prefer }}-${{ hashFiles('modules/civiremote_case/**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-

- name: Install dependencies
run: |
composer update --no-progress --prefer-dist --${{ matrix.prefer }} --optimize-autoloader &&
composer composer-phpstan -- update --no-progress --prefer-dist --optimize-autoloader &&
composer --working-dir=ci update --no-progress --prefer-dist --${{ matrix.prefer }} --optimize-autoloader

- name: Run PHPStan
run: composer phpstan -- analyse -c phpstan.ci.neon
2 changes: 2 additions & 0 deletions modules/civiremote_case/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The dependencies specified in composer.json of this directory are required to
run phpstan in CI.
21 changes: 21 additions & 0 deletions modules/civiremote_case/ci/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/systopia/drupal-json_forms.git"
},
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"drupal/core": "^10",
"drupal/json_forms": "~0.1"
}
}
10 changes: 10 additions & 0 deletions modules/civiremote_case/civiremote_case.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: CiviRemote Case
type: module
description: 'CiviRemote Case'
package: CiviCRM
core_version_requirement: ^10
dependencies:
- civiremote_entity

project: civiremote
version: 1.1.x-dev
2 changes: 2 additions & 0 deletions modules/civiremote_case/civiremote_case.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
access civiremote case:
title: 'Access Cases in CiviCRM'
25 changes: 25 additions & 0 deletions modules/civiremote_case/civiremote_case.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
civiremote_case.create_form:
path: '/civiremote/case/add/{profile}'
defaults:
_controller: 'Drupal\civiremote_case\Controller\CaseCreateController::form'
options:
no_cache: TRUE
parameters:
profile:
type: string
requirements:
_permission: 'access civiremote case'

civiremote_case.update_form:
path: '/civiremote/case/{id}/update/{profile}'
defaults:
_controller: 'Drupal\civiremote_case\Controller\CaseUpdateController::form'
options:
no_cache: TRUE
parameters:
id:
type: int
profile:
type: string
requirements:
_permission: 'access civiremote case'
23 changes: 23 additions & 0 deletions modules/civiremote_case/civiremote_case.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
services:
_defaults:
autowire: true
public: false # Controller classes and services directly fetched from container need to be public

Drupal\civiremote_case\Api\CaseApi:
class: Drupal\civiremote_case\Api\CaseApi

Drupal\civiremote_case\Controller\CaseCreateController:
class: Drupal\civiremote_case\Controller\CaseCreateController
public: true

Drupal\civiremote_case\Controller\CaseUpdateController:
class: Drupal\civiremote_case\Controller\CaseUpdateController
public: true

Drupal\civiremote_case\Form\RequestHandler\CaseCreateFormRequestHandler:
class: Drupal\civiremote_case\Form\RequestHandler\CaseCreateFormRequestHandler
public: true

Drupal\civiremote_case\Form\RequestHandler\CaseUpdateFormRequestHandler:
class: Drupal\civiremote_case\Form\RequestHandler\CaseUpdateFormRequestHandler
public: true
69 changes: 69 additions & 0 deletions modules/civiremote_case/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"name": "custom/civiremote_case",
"description": "Drupal frontend to access CiviCRM Remote Case.",
"type": "drupal-custom-module",
"license": "AGPL-3.0-only",
"authors": [
{
"name": "SYSTOPIA GmbH",
"email": "info@systopia.de"
}
],
"autoload": {
"psr-4": {
"Drupal\\civiremote_case\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Drupal\\Tests\\civiremote_case\\": "tests/src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true,
"php-http/discovery": false
}
},
"repositories": [
{
"type": "composer",
"url": "https://packages.drupal.org/8"
}
],
"require": {
"php": "^8.1"
},
"require-dev": {
"drupal/core-dev": "^10"
},
"scripts": {
"composer-phpstan": [
"@composer --working-dir=tools/phpstan"
],
"composer-tools": [
"@composer-phpstan"
],
"phpcs": [
"@php vendor/bin/phpcs"
],
"phpcbf": [
"@php vendor/bin/phpcbf"
],
"phpstan": [
"@php tools/phpstan/vendor/bin/phpstan"
],
"phpunit": [
"@php vendor/bin/phpunit --coverage-text"
],
"test": [
"@phpcs",
"@phpstan",
"@phpunit"
]
}
}
80 changes: 80 additions & 0 deletions modules/civiremote_case/phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="CiviCRM - PHPStan"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<file>src</file>

<arg name="extensions" value="php"/>
<arg name="cache" value=".phpcs.cache"/>
<arg name="colors"/>
<arg value="sp"/>

<!-- Exit with code 0 if warnings, but no error occurred -->
<config name="ignore_warnings_on_exit" value="true"/>

<rule ref="vendor/drupal/coder/coder_sniffer/Drupal">
<!-- Don't enforce phpdoc type hint because it (might) only duplicate a PHP type hint -->
<exclude name="Drupal.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="Drupal.Commenting.FunctionComment.MissingReturnComment"/>

<!-- Don't enforce comments -->
<exclude name="Drupal.Commenting.VariableComment.Missing"/>
<exclude name="Drupal.Commenting.ClassComment.Missing"/>
<exclude name="Drupal.Commenting.FunctionComment.Missing"/>
<exclude name="Drupal.Commenting.DocComment.MissingShort"/>

<!-- Allow "/** @phpstan-var ... */" -->
<exclude name="Drupal.Commenting.InlineComment.DocBlock"/>

<!-- False positive with license header -->
<exclude name="Drupal.Commenting.FileComment.NamespaceNoFileDoc"/>
</rule>

<rule ref="vendor/drupal/coder/coder_sniffer/DrupalPractice"/>

<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<rule ref="Generic.CodeAnalysis.EmptyStatement">
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
</rule>
<rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>
<rule ref="Generic.Files.OneClassPerFile"/>
<rule ref="Generic.Files.OneInterfacePerFile"/>
<rule ref="Generic.Files.OneObjectStructurePerFile"/>
<rule ref="Generic.Files.OneTraitPerFile"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Metrics.CyclomaticComplexity"/>
<rule ref="Generic.Metrics.NestingLevel"/>
<rule ref="Generic.NamingConventions.AbstractClassNamePrefix"/>
<rule ref="Generic.NamingConventions.InterfaceNameSuffix"/>
<rule ref="Generic.NamingConventions.TraitNameSuffix"/>
<rule ref="Generic.PHP.RequireStrictTypes"/>
<rule ref="PSR1.Files.SideEffects"/>
<rule ref="PSR12.Classes.ClassInstantiation"/>
<rule ref="PSR12.Properties.ConstantVisibility"/>
<rule ref="Squiz.PHP.CommentedOutCode"/>
<rule ref="Squiz.PHP.GlobalKeyword"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage">
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
</rule>

<!-- Lines can be 120 chars long, but never show errors -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>

<!-- Ban some functions -->
<rule ref="Generic.PHP.ForbiddenFunctions">
<properties>
<property name="forbiddenFunctions" type="array">
<element key="sizeof" value="count"/>
<element key="delete" value="unset"/>
<element key="print" value="echo"/>
<element key="is_null" value="null"/>
<element key="create_function" value="null"/>
</property>
</properties>
</rule>
</ruleset>
6 changes: 6 additions & 0 deletions modules/civiremote_case/phpstan.ci.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
includes:
- phpstan.neon.dist

parameters:
bootstrapFiles:
- ci/vendor/autoload.php
26 changes: 26 additions & 0 deletions modules/civiremote_case/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
parameters:
paths:
- src
bootstrapFiles:
- vendor/autoload.php
scanDirectories:
- ../civiremote_entity/src
level: 9
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
checkMissingCallableSignature: true
treatPhpDocTypesAsCertain: false
exceptions:
check:
missingCheckedExceptionInThrows: true
tooWideThrowType: true
checkedExceptionClasses:
- \Assert\AssertionFailedException
implicitThrows: false
ignoreErrors:
# Note paths are prefixed with ""*/" to work with inspections in PHPStorm because of:
# https://youtrack.jetbrains.com/issue/WI-63891/PHPStan-ignoreErrors-configuration-isnt-working-with-inspections
# Happens in classes implementing ContainerInjectionInterface::create()
- '/ constructor expects [^\s]+, object(\|null)? given.$/'

tmpDir: .phpstan
9 changes: 9 additions & 0 deletions modules/civiremote_case/phpstan.neon.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copy this file to phpstan.neon and replace {VENDOR_DIR} with the vendor
# directory of your Drupal project.

includes:
- phpstan.neon.dist

parameters:
bootstrapFiles:
- {VENDOR_DIR}/autoload.php
Loading
Loading