Issues (146)

examples/musicbrainz.php (4 issues)

1
<?php
2
/**
3
 * Do an XML lookup from MusicBrainz.
4
 *
5
 * This example shows how to make a simple REST-style request against a remote
6
 * server. (For a more advanced example of HTML requests, see {@link sparql.php})
7
 *
8
 * This does two HTTP requests -- one to get information about a band, and another
9
 * to get a list of albums put out by that band.
10
 * 
11
 * TODO: Fix the output.
12
 *
13
 * 
14
 * @author M Butcher <[email protected]>
15
 * @license LGPL The GNU Lesser GPL (LGPL) or an MIT-like license.
16
 * @see http://musicbrainz.org
17
 */
18
require_once '../src/QueryPath/QueryPath.php';
19
20
$artist_url = 'http://musicbrainz.org/ws/1/artist/?type=xml&name=u2';
21
$album_url = 'http://musicbrainz.org/ws/1/release/?type=xml&artistid=';
22
try {
23
  $artist = qp($artist_url, 'artist:first');
24
  if ($artist->size() > 0) {
0 ignored issues
show
Deprecated Code introduced by
The function QueryPath\DOMQuery::size() has been deprecated: QueryPath now implements Countable, so use count(). ( Ignorable by Annotation )

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

24
  if (/** @scrutinizer ignore-deprecated */ $artist->size() > 0) {

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...
25
    $id = $artist->attr('id');
26
    print '<p>The best match we found was for ' . $artist->children('name')->text() . PHP_EOL;
0 ignored issues
show
Are you sure $artist->children('name')->text() of type QueryPath\DOMQuery|string can be used in concatenation? ( Ignorable by Annotation )

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

26
    print '<p>The best match we found was for ' . /** @scrutinizer ignore-type */ $artist->children('name')->text() . PHP_EOL;
Loading history...
27
    print '</p><p>Artist ID: ' . $id . PHP_EOL;
0 ignored issues
show
Are you sure $id of type QueryPath\DOMQuery|mixed|null can be used in concatenation? ( Ignorable by Annotation )

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

27
    print '</p><p>Artist ID: ' . /** @scrutinizer ignore-type */ $id . PHP_EOL;
Loading history...
28
    print '</p><p>Albums for this artist' . PHP_EOL;
29
    print '</p><p><a href="'.$album_url . urlencode($id).'">'.$album_url.'</a></p>';
0 ignored issues
show
It seems like $id can also be of type QueryPath\DOMQuery and null; however, parameter $string of urlencode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

29
    print '</p><p><a href="'.$album_url . urlencode(/** @scrutinizer ignore-type */ $id).'">'.$album_url.'</a></p>';
Loading history...
30
    $albums = qp($album_url . urlencode($id))->writeXML();
31
    
32
    foreach ($albums as $album) {
33
      print $album->find('title')->text() . PHP_EOL;
34
      // Fixme: Label is broken. See Drupal QueryPath module.
35
      print '(' . $album->next('label')->text() . ')' .PHP_EOL;
36
    }
37
  }
38
}
39
catch (Exception $e) {
40
  print $e->getMessage();
41
}
42