| Conditions | 10 |
| Paths | 3 |
| Total Lines | 137 |
| Code Lines | 88 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 62 | function content_negociated_user_home (&$params) { |
||
| 63 | $username = $params['username']; |
||
| 64 | $accept = $params['accept']; |
||
| 65 | |||
| 66 | if($accept == 'application/rdf+xml') { |
||
| 67 | $params['content_type'] = 'application/rdf+xml'; |
||
| 68 | |||
| 69 | $user_obj = user_get_object_by_name($username); |
||
| 70 | |||
| 71 | $user_real_name = $user_obj->getRealName(); |
||
| 72 | $user_email = $user_obj->getEmail(); |
||
| 73 | $mbox = 'mailto:'.$user_email; |
||
| 74 | $mbox_sha1sum = sha1($mbox); |
||
| 75 | |||
| 76 | $projects = $user_obj->getGroups() ; |
||
| 77 | sortProjectList($projects) ; |
||
| 78 | $roles = RBACEngine::getInstance()->getAvailableRolesForUser($user_obj) ; |
||
| 79 | sortRoleList($roles) ; |
||
| 80 | |||
| 81 | // Construct an ARC2_Resource containing the project's RDF (DOAP) description |
||
| 82 | $ns = array( |
||
| 83 | 'rdf' => 'http://www.w3.org/1999/02/22-rdf-syntax-ns#', |
||
| 84 | 'rdfs' => 'http://www.w3.org/2000/01/rdf-schema#', |
||
| 85 | 'foaf' => 'http://xmlns.com/foaf/0.1/', |
||
| 86 | 'sioc' => 'http://rdfs.org/sioc/ns#', |
||
| 87 | 'doap' => 'http://usefulinc.com/ns/doap#', |
||
| 88 | 'dcterms' => 'http://purl.org/dc/terms/', |
||
| 89 | 'planetforge' => 'http://coclico-project.org/ontology/planetforge#' |
||
| 90 | ); |
||
| 91 | |||
| 92 | $conf = array( |
||
| 93 | 'ns' => $ns |
||
| 94 | ); |
||
| 95 | |||
| 96 | // First, let's deal with the account |
||
| 97 | $account_res = ARC2::getResource($conf); |
||
| 98 | $account_uri = util_make_url_u($username, $user_obj->getID()); |
||
| 99 | $account_uri = rtrim($account_uri,'/'); |
||
| 100 | $person_uri = $account_uri . '#person'; |
||
| 101 | |||
| 102 | $account_res->setURI( $account_uri ); |
||
| 103 | // $account_res->setRel('rdf:type', 'foaf:OnlineAccount'); |
||
| 104 | rdfutils_setPropToUri($account_res, 'rdf:type', 'foaf:OnlineAccount'); |
||
| 105 | rdfutils_setPropToUri($account_res, 'foaf:accountServiceHomepage', $account_uri . '/'); |
||
| 106 | $account_res->setProp('foaf:accountName', $username); |
||
| 107 | rdfutils_setPropToUri($account_res, 'sioc:account_of', $person_uri); |
||
| 108 | rdfutils_setPropToUri($account_res, 'foaf:accountProfilePage', $account_uri); |
||
| 109 | |||
| 110 | $groups_index = array(); |
||
| 111 | $projects_index = array(); |
||
| 112 | $roles_index = array(); |
||
| 113 | |||
| 114 | $usergroups_uris = array(); |
||
| 115 | // see if there were any groups |
||
| 116 | if (count($projects) >= 1) { |
||
| 117 | foreach ($projects as $p) { |
||
| 118 | // TODO : report also private projects if authenticated, for instance through OAuth |
||
| 119 | if($p->isPublic()) { |
||
| 120 | $project_link = util_make_link_g ($p->getUnixName(),$p->getID(),$p->getPublicName()); |
||
| 121 | $project_uri = util_make_url_g ($p->getUnixName(),$p->getID()); |
||
| 122 | // sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/ |
||
| 123 | $usergroup_uri = $project_uri .'members/'; |
||
| 124 | |||
| 125 | $role_names = array(); |
||
| 126 | |||
| 127 | $usergroups_uris[] = $usergroup_uri; |
||
| 128 | |||
| 129 | $usergroup_res = ARC2::getResource($conf); |
||
| 130 | $usergroup_res->setURI( $usergroup_uri ); |
||
| 131 | rdfutils_setPropToUri($usergroup_res, 'rdf:type', 'sioc:UserGroup'); |
||
| 132 | rdfutils_setPropToUri($usergroup_res, 'sioc:usergroup_of', $project_uri); |
||
| 133 | |||
| 134 | $roles_uris = array(); |
||
| 135 | foreach ($roles as $r) { |
||
| 136 | if ($r instanceof RoleExplicit |
||
|
|
|||
| 137 | && $r->getHomeProject() != NULL |
||
| 138 | && $r->getHomeProject()->getID() == $p->getID()) { |
||
| 139 | $role_names[$r->getID()] = $r->getName() ; |
||
| 140 | $role_uri = $project_uri .'roles/'.$r->getID(); |
||
| 141 | |||
| 142 | $roles_uris[] = $role_uri; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | rdfutils_setPropToUri($usergroup_res, 'planetforge:group_has_function', $roles_uris); |
||
| 146 | |||
| 147 | $project_res = ARC2::getResource($conf); |
||
| 148 | $project_res->setURI( $project_uri ); |
||
| 149 | rdfutils_setPropToUri($project_res, 'rdf:type', 'planetforge:ForgeProject'); |
||
| 150 | $project_res->setProp('doap:name', $p->getUnixName()); |
||
| 151 | |||
| 152 | $projects_index = ARC2::getMergedIndex($projects_index, $project_res->index); |
||
| 153 | |||
| 154 | |||
| 155 | foreach ($role_names as $id => $name) { |
||
| 156 | $role_res = ARC2::getResource($conf); |
||
| 157 | $role_res->setURI( $project_uri .'roles/'.$id ); |
||
| 158 | rdfutils_setPropToUri($role_res, 'rdf:type', 'sioc:Role'); |
||
| 159 | $role_res->setProp('sioc:name', $name); |
||
| 160 | |||
| 161 | $roles_index = ARC2::getMergedIndex($roles_index, $role_res->index); |
||
| 162 | } |
||
| 163 | |||
| 164 | $groups_index = ARC2::getMergedIndex($groups_index, $usergroup_res->index); |
||
| 165 | |||
| 166 | } |
||
| 167 | } |
||
| 168 | } // end if groups |
||
| 169 | rdfutils_setPropToUri($account_res, 'sioc:member_of', $usergroups_uris); |
||
| 170 | |||
| 171 | // next, deal with the person |
||
| 172 | $person_res = ARC2::getResource($conf); |
||
| 173 | |||
| 174 | $person_res->setURI( $person_uri ); |
||
| 175 | rdfutils_setPropToUri($person_res, 'rdf:type', 'foaf:Person'); |
||
| 176 | $person_res->setProp('foaf:name', $user_real_name); |
||
| 177 | rdfutils_setPropToUri($person_res, 'foaf:holdsAccount', $account_uri); |
||
| 178 | $person_res->setProp('foaf:mbox_sha1sum', $mbox_sha1sum); |
||
| 179 | |||
| 180 | // merge the two sets of triples |
||
| 181 | $merged_index = ARC2::getMergedIndex($account_res->index, $person_res->index); |
||
| 182 | $merged_index = ARC2::getMergedIndex($merged_index, $groups_index); |
||
| 183 | $merged_index = ARC2::getMergedIndex($merged_index, $projects_index); |
||
| 184 | $merged_index = ARC2::getMergedIndex($merged_index, $roles_index); |
||
| 185 | |||
| 186 | $conf = array( |
||
| 187 | 'ns' => $ns, |
||
| 188 | 'serializer_type_nodes' => true |
||
| 189 | ); |
||
| 190 | |||
| 191 | $ser = ARC2::getRDFXMLSerializer($conf); |
||
| 192 | |||
| 193 | /* Serialize a resource index */ |
||
| 194 | $doc = $ser->getSerializedIndex($merged_index); |
||
| 195 | |||
| 196 | $params['content'] = $doc . "\n"; |
||
| 197 | } |
||
| 198 | } |
||
| 199 | } |
||
| 205 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.