Struct Types
Squashed commit of the following: commit 74ed84617fcbecf661695763323e50d049a88db7 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:46:29 2018 +0000 Test passes so remove the dump statement commit a7d3323be02da64f76e8ec88713e3de84a13ded7 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:40:35 2018 +0000 Values with spaces need to be quoted commit 58a120bb238f14346793c388b948b7351d3b51fd Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:37:23 2018 +0000 We need a diplay name for the tests to work now we are using strict type checking commit b46f177053bd697db9a4835d073f2f37e088b26f Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:31:29 2018 +0000 Get travis to show more info about failing test commit 60323f3ce5a0561329a1721ee94821571cdcc86a Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:23:27 2018 +0000 Remove un-used namnepsace imports commit 096d3505920bc94ff8677c77430eca0aae0be58a Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:21:55 2018 +0000 we need php7.2 for object type-hint commit bb818bc19c73d02d510af9f002199f5718a54608 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Jan 15 12:15:48 2018 +0000 Added lots of strict_types
This commit is contained in:
parent
053e19a457
commit
e4fe2ecde3
64 changed files with 911 additions and 406 deletions
|
@ -1,21 +1,25 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use App\Models\Contact;
|
||||
use Illuminate\View\View;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
class ContactsController extends Controller
|
||||
{
|
||||
/**
|
||||
* List the currect contacts that can be edited.
|
||||
*
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function index()
|
||||
public function index(): View
|
||||
{
|
||||
$contacts = Contact::all();
|
||||
|
||||
|
@ -25,9 +29,9 @@ class ContactsController extends Controller
|
|||
/**
|
||||
* Display the form to add a new contact.
|
||||
*
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create()
|
||||
public function create(): View
|
||||
{
|
||||
return view('admin.contacts.create');
|
||||
}
|
||||
|
@ -35,17 +39,16 @@ class ContactsController extends Controller
|
|||
/**
|
||||
* Process the request to add a new contact.
|
||||
*
|
||||
* @param \Illuminate\Http|request $request
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
public function store(): RedirectResponse
|
||||
{
|
||||
$contact = new Contact();
|
||||
$contact->name = $request->input('name');
|
||||
$contact->nick = $request->input('nick');
|
||||
$contact->homepage = $request->input('homepage');
|
||||
$contact->twitter = $request->input('twitter');
|
||||
$contact->facebook = $request->input('facebook');
|
||||
$contact->name = request()->input('name');
|
||||
$contact->nick = request()->input('nick');
|
||||
$contact->homepage = request()->input('homepage');
|
||||
$contact->twitter = request()->input('twitter');
|
||||
$contact->facebook = request()->input('facebook');
|
||||
$contact->save();
|
||||
|
||||
return redirect('/admin/contacts');
|
||||
|
@ -54,10 +57,10 @@ class ContactsController extends Controller
|
|||
/**
|
||||
* Show the form to edit an existing contact.
|
||||
*
|
||||
* @param string The contact id
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @param int $contactId
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function edit($contactId)
|
||||
public function edit(int $contactId): View
|
||||
{
|
||||
$contact = Contact::findOrFail($contactId);
|
||||
|
||||
|
@ -69,28 +72,27 @@ class ContactsController extends Controller
|
|||
*
|
||||
* @todo Allow saving profile pictures for people without homepages
|
||||
*
|
||||
* @param string The contact id
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @param int $contactId
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update($contactId, Request $request)
|
||||
public function update(int $contactId): RedirectResponse
|
||||
{
|
||||
$contact = Contact::findOrFail($contactId);
|
||||
$contact->name = $request->input('name');
|
||||
$contact->nick = $request->input('nick');
|
||||
$contact->homepage = $request->input('homepage');
|
||||
$contact->twitter = $request->input('twitter');
|
||||
$contact->facebook = $request->input('facebook');
|
||||
$contact->name = request()->input('name');
|
||||
$contact->nick = request()->input('nick');
|
||||
$contact->homepage = request()->input('homepage');
|
||||
$contact->twitter = request()->input('twitter');
|
||||
$contact->facebook = request()->input('facebook');
|
||||
$contact->save();
|
||||
|
||||
if ($request->hasFile('avatar') && ($request->input('homepage') != '')) {
|
||||
$dir = parse_url($request->input('homepage'), PHP_URL_HOST);
|
||||
if (request()->hasFile('avatar') && (request()->input('homepage') != '')) {
|
||||
$dir = parse_url(request()->input('homepage'), PHP_URL_HOST);
|
||||
$destination = public_path() . '/assets/profile-images/' . $dir;
|
||||
$filesystem = new Filesystem();
|
||||
if ($filesystem->isDirectory($destination) === false) {
|
||||
$filesystem->makeDirectory($destination);
|
||||
}
|
||||
$request->file('avatar')->move($destination, 'image');
|
||||
request()->file('avatar')->move($destination, 'image');
|
||||
}
|
||||
|
||||
return redirect('/admin/contacts');
|
||||
|
@ -99,10 +101,10 @@ class ContactsController extends Controller
|
|||
/**
|
||||
* Process the request to delete a contact.
|
||||
*
|
||||
* @param string The contact id
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @param int $contactId
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy($contactId)
|
||||
public function destroy(int $contactId): RedirectResponse
|
||||
{
|
||||
$contact = Contact::findOrFail($contactId);
|
||||
$contact->delete();
|
||||
|
@ -116,16 +118,16 @@ class ContactsController extends Controller
|
|||
* This method attempts to find the microformat marked-up profile image
|
||||
* from a given homepage and save it accordingly
|
||||
*
|
||||
* @param string The contact id
|
||||
* @return \Illuminate\View\Factory view
|
||||
* @param int $contactId
|
||||
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function getAvatar($contactId)
|
||||
public function getAvatar(int $contactId)
|
||||
{
|
||||
// Initialising
|
||||
$avatarURL = null;
|
||||
$avatar = null;
|
||||
$contact = Contact::findOrFail($contactId);
|
||||
if (mb_strlen($contact->homepage !== null) !== 0) {
|
||||
if ($contact->homepage !== null && mb_strlen($contact->homepage) !== 0) {
|
||||
$client = resolve(Client::class);
|
||||
try {
|
||||
$response = $client->get($contact->homepage);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue