Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Korko
SecretSanta.fr
Commits
5d40db31
Commit
5d40db31
authored
Dec 22, 2016
by
Jérémy Lemesle
Committed by
GitHub
Dec 22, 2016
Browse files
Merge pull request #24 from Korko/analysis-qv0JaV
Apply fixes from StyleCI
parents
408d0ab3
7ce27f00
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/RandomFormController.php
View file @
5d40db31
...
...
@@ -5,8 +5,8 @@ namespace Korko\SecretSanta\Http\Controllers;
use
Illuminate\Http\Request
;
use
Korko\SecretSanta\Http\Requests\RandomFormRequest
;
use
Mail
;
use
Solver
;
use
Sms
;
use
Solver
;
use
Statsd
;
class
RandomFormController
extends
Controller
...
...
app/Libs/HatSolver.php
View file @
5d40db31
...
...
@@ -13,9 +13,10 @@ class HatSolver
shuffle
(
$hat
);
$generator
=
$this
->
getGenerator
(
$participants
,
$exclusions
,
$hat
);
if
(
!
$generator
->
valid
())
{
if
(
!
$generator
->
valid
())
{
throw
new
Exception
(
'Cannot solve'
);
}
return
$generator
->
current
();
}
...
...
@@ -24,7 +25,7 @@ class HatSolver
$combinations
=
[];
$generator
=
$this
->
getGenerator
(
$participants
,
$exclusions
,
array_keys
(
$participants
));
foreach
(
$generator
as
$combination
)
{
foreach
(
$generator
as
$combination
)
{
$combinations
[]
=
$combination
;
}
...
...
@@ -41,12 +42,12 @@ class HatSolver
$actualExclusions
=
array_key_exists
(
$i
,
$exclusions
)
?
$exclusions
[
$i
]
:
[];
$actualHat
=
array_diff
(
$hat
,
$actualExclusions
,
[
$i
]);
if
(
$actualHat
!==
[])
{
foreach
(
$actualHat
as
$possibility
)
{
if
(
$actualHat
!==
[])
{
foreach
(
$actualHat
as
$possibility
)
{
$possibilityCombination
=
$combination
+
[
$i
=>
$possibility
];
$possibilityHat
=
array_diff
(
$hat
,
[
$possibility
]);
if
(
$possibilityHat
===
[])
{
if
(
$possibilityHat
===
[])
{
yield
$possibilityCombination
;
}
else
{
yield
from
$this
->
_solve
(
$i
+
1
,
$possibilityCombination
,
$exclusions
,
$possibilityHat
);
...
...
resources/lang/fr/message.php
View file @
5d40db31
<?php
return
[
'sent'
=>
'Envoyé avec succès !'
'sent'
=>
'Envoyé avec succès !'
,
];
tests/SolverTest.php
View file @
5d40db31
...
...
@@ -8,6 +8,7 @@ class SolverTest extends TestCase
array_walk
(
$el
,
function
(
&
$idx
)
use
(
$participants
)
{
$idx
=
$participants
[
$idx
];
});
return
implode
(
''
,
$el
);
},
$test
);
$this
->
assertEquals
(
sort
(
$valid
),
sort
(
$test
));
...
...
@@ -63,6 +64,7 @@ class SolverTest extends TestCase
$rand2
=
rand
(
0
,
10
);
if
(
$rand1
!==
$rand2
)
{
$this
->
markTestSkipped
(
'srand disabled'
);
return
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment