Passed
Pull Request — develop (#924)
by
unknown
07:25
created

RApiHalHelperSiteContent   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 20
c 1
b 0
f 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A save() 0 28 4
1
<?php
2
/**
3
 * @package     Redcore
4
 * @subpackage  Api
5
 *
6
 * @copyright   Copyright (C) 2008 - 2021 redWEB.dk. All rights reserved.
7
 * @license     GNU General Public License version 2 or later, see LICENSE.
8
 */
9
10
defined('JPATH_BASE') or die;
11
12
/**
13
 * Api Helper class for overriding default methods
14
 *
15
 * @package     Redcore
16
 * @subpackage  Api Helper
17
 * @since       1.8
18
 */
19
class RApiHalHelperSiteContent
20
{
21
	/**
22
	 * Service for creating content.
23
	 *
24
	 * @param   string  $data  content
25
	 *
26
	 * @return  boolean         True on success. False otherwise.
27
	 */
28
	public function save($data)
29
	{
30
		if (version_compare(JVERSION, '3.0', 'lt')) {
31
			JTable::addIncludePath(JPATH_PLATFORM . 'joomla/database/table');
32
		}
33
		
34
		$data = (object) $data;
35
		$article = JTable::getInstance('content');
36
		$article->title            = $data->title;
0 ignored issues
show
Bug Best Practice introduced by
The property title does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
//		$article->alias            = JFilterOutput::stringURLSafe(time());
38
		$article->alias            = JFilterOutput::stringURLSafe($data->title);
39
		$article->introtext        = '<p>'.$data->description.'</p>';
40
		$article->created          = JFactory::getDate()->toSQL();;
41
		$article->created_by_alias = $data->user;
0 ignored issues
show
Bug introduced by
The property created_by_alias does not seem to exist on JTable.
Loading history...
42
		$article->state            = 1;
43
		$article->access           = 1;
0 ignored issues
show
Bug Best Practice introduced by
The property access does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
44
		$article->metadata         = '{"page_title":"'.$data->title.'","author":"'.$data->user.'","robots":""}';
45
		$article->language         = '*';
0 ignored issues
show
Bug introduced by
The property language does not seem to exist on JTable.
Loading history...
46
//		$article->catid            = 1;
47
		
48
		if (!$article->check()) {
49
			throw new Exception($article->getError());
0 ignored issues
show
Deprecated Code introduced by
The function JObject::getError() has been deprecated: 12.3 JError has been deprecated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

49
			throw new Exception(/** @scrutinizer ignore-deprecated */ $article->getError());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
50
			return FALSE;
0 ignored issues
show
Unused Code introduced by
return FALSE is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
51
		}
52
		
53
		if (!$article->store(TRUE)) {
54
			throw new Exception($article->getError());
0 ignored issues
show
Deprecated Code introduced by
The function JObject::getError() has been deprecated: 12.3 JError has been deprecated ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

54
			throw new Exception(/** @scrutinizer ignore-deprecated */ $article->getError());

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
			return FALSE;
56
		}
57
	}
58
}
59