Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gammamatrix authored May 21, 2024
1 parent c1d653d commit fb27707
Show file tree
Hide file tree
Showing 49 changed files with 935 additions and 252 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
# These database components are for testing only.
/database/factories export-ignore
/database/migrations-laravel export-ignore
/database/migrations-playground export-ignore
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
.DS_Store
*/.DS_Store

.derp
*.derp

Homestead.yaml
Homestead.json
Expand Down Expand Up @@ -63,6 +63,8 @@ public/tests

phpunit.xml

phpstan.neon

.phpunit.cache

tests/_output/*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test": "vendor/bin/testbench package:test",
"format": "vendor/bin/php-cs-fixer fix",
"analyse": "vendor/bin/phpstan analyse --verbose --debug --level max"
}
Expand Down
47 changes: 47 additions & 0 deletions config/playground-matrix.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
<?php
/**
* Playground
*/

declare(strict_types=1);

/**
* Configuration and Environment Variables
*/
return [

/*
|--------------------------------------------------------------------------
| About Information
|--------------------------------------------------------------------------
|
| By default, information will be displayed about this package when using:
|
| `artisan about`
|
*/

'about' => (bool) env('PLAYGROUND_MATRIX_ABOUT', true),

/*
|--------------------------------------------------------------------------
| Loading
|--------------------------------------------------------------------------
|
| By default, migrations are disabled.
|
*/

'load' => [
'migrations' => (bool) env('PLAYGROUND_MATRIX_LOAD_MIGRATIONS', false),
],

/*
|--------------------------------------------------------------------------
| Projects and tickets
|--------------------------------------------------------------------------
|
| The default key to use for tickets.
| This is not case-sensitive, queries use LIKE.
|
| Examples: GH, TICKET, SomeThing, Dashes-are-OK
| - emojis technically should work, but it may be a bad UX in the UI.
*/

'keys' => [
'default' => env('PLAYGROUND_MATRIX_KEYS_DEFAULT', ''),

'allow_empty' => (bool) env('PLAYGROUND_MATRIX_KEYS_ALLOW_EMPTY', true),
],

];
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function up(): void
$table->boolean('closed')->default(0);
$table->boolean('completed')->default(0);
$table->boolean('cron')->default(0)->index();
$table->boolean('duplicate')->default(0);
$table->boolean('fixed')->default(0);
$table->boolean('flagged')->default(0);
$table->boolean('internal')->default(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ public function up(): void
$table->boolean('closed')->default(0);
$table->boolean('completed')->default(0);
$table->boolean('cron')->default(0)->index();
$table->boolean('fixed')->default(0);
$table->boolean('flagged')->default(0);
$table->boolean('fixed')->default(0);
$table->boolean('internal')->default(0);
$table->boolean('locked')->default(0);
$table->boolean('pending')->default(0);
$table->boolean('planned')->default(0);
$table->boolean('problem')->default(0);
$table->boolean('published')->default(0);
$table->boolean('released')->default(0);
$table->boolean('retired')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('retired')->default(0);
$table->boolean('suspended')->default(0);
$table->boolean('unknown')->default(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public function up(): void
$table->boolean('problem')->default(0);
$table->boolean('published')->default(0);
$table->boolean('released')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('suspended')->default(0);
$table->boolean('unknown')->default(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function up(): void
$table->boolean('problem')->default(0);
$table->boolean('published')->default(0);
$table->boolean('released')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('retired')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('suspended')->default(0);
$table->boolean('unknown')->default(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public function up(): void
$table->boolean('problem')->default(0);
$table->boolean('published')->default(0);
$table->boolean('released')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('retired')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('suspended')->default(0);
$table->boolean('unknown')->default(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public function up(): void
$table->boolean('problem')->default(0);
$table->boolean('published')->default(0);
$table->boolean('released')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('retired')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('special')->default(0);
$table->boolean('suspended')->default(0);
$table->boolean('unknown')->default(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public function up(): void
$table->boolean('problem')->default(0);
$table->boolean('published')->default(0);
$table->boolean('released')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('retired')->default(0);
$table->boolean('resolved')->default(0);
$table->boolean('suspended')->default(0);
$table->boolean('unknown')->default(0);

Expand Down
3 changes: 2 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ parameters:

treatPhpDocTypesAsCertain: false

checkGenericClassInNonGenericObjectType: false
# editorUrl: 'vscode://file/%%file%%:%%line%%'
# editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
2 changes: 1 addition & 1 deletion phpunit.xml.dev
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<env name="APP_DEBUG" value="false" />
<env name="APP_ENV" value="testing" />
<env name="APP_KEY" value="base64:lNTGdmOOxP5uNUVuCj9FB//Ssn8JmRXBdtPEE4/QReE=" />
<env name="AUTH_PROVIDERS_USERS_MODEL" value="Playground\Test\Models\User" />
<env name="AUTH_MODEL" value="Playground\Models\User" />
<env name="BCRYPT_ROUNDS" value="4" />
<env name="CACHE_DRIVER" value="array" />
<env name="DB_CONNECTION" value="sqlite" />
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<env name="APP_DEBUG" value="false" />
<env name="APP_ENV" value="testing" />
<env name="APP_KEY" value="base64:lNTGdmOOxP5uNUVuCj9FB//Ssn8JmRXBdtPEE4/QReE=" />
<env name="AUTH_PROVIDERS_USERS_MODEL" value="Playground\Test\Models\User" />
<env name="AUTH_MODEL" value="Playground\Models\User" />
<env name="BCRYPT_ROUNDS" value="4" />
<env name="CACHE_DRIVER" value="array" />
<env name="DB_CONNECTION" value="sqlite" />
Expand Down
61 changes: 61 additions & 0 deletions src/Concerns/Creating.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Playground
*/

declare(strict_types=1);
namespace Playground\Matrix\Concerns;

use Playground\Matrix\Models\Ticket;

/**
* \Playground\Matrix\Concerns\Creating
*/
trait Creating
{
protected function getProjectKey(Ticket $ticket): string
{
$key = config('playground-matrix.keys.default');
$key = is_string($key) ? $key : '';

$project = $ticket->project_id ? $ticket->project()->first() : null;

if ($project) {
if (! $project->key) {
if (config('playground-matrix.keys.allow_empty')) {
$key = '';
}
} else {
$key = $project->key;
}
}

return $key;
}

protected function handleTicketCode(Ticket $ticket): void
{
if (empty($ticket->project_id)) {
return;
}

$ticket->key = $this->getProjectKey($ticket);

if (! $ticket->key && ! config('playground-matrix.keys.allow_empty')) {
return;
}

$code = Ticket::where('key', 'LIKE', $ticket->key)->max('code');
$next = $code > 0 ? ++$code : 1;
$slug = sprintf(
'%1$s%2$s%3$d',
$ticket->key,
$ticket->key ? '-' : '',
$next
);

$ticket->code = $next;
$ticket->slug = $slug;
$ticket->key_code_hash = md5($slug);
}
}
Loading

0 comments on commit fb27707

Please sign in to comment.